@noldova/code.editor.diff.angular 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -4,12 +4,32 @@ The code editor's diff view in Angular: `DiffEditorComponent`, the `noldova-diff
4
4
  It colors both texts by its `language`, an id or a definition, as the code view does, shows the changed lines and characters, folds the unchanged regions, keeps the modified side editable unless it is read-only and the original read-only unless asked, and moves between changes with the `diffEditor.nextChange` and `diffEditor.previousChange` commands, on Alt with Down and Up, or `nextChange` and `previousChange`.
5
5
  Its `DiffEditorContribution` adds those commands, their keys, the `inDiffEditor` condition and the `DiffEditorSettings` to the app's `CodeEditorRegistries`: `diff.contextLines`, the unchanged lines kept next to a change; `diff.minimumHiddenLines`, the fewest lines a fold hides; `diff.characterDiffLimit`, the most characters compared by character; and `diff.inlineBreakpoint`, the width in rem below which the automatic layout is inline.
6
6
  A host sets them, and rebinds the keys, in `CodeEditorRegistries` like any other setting or key.
7
+ A host draws its own bars at each change, such as its actions for that change, through `bars`, an `IDiffBars` that gives each change its `DiffBar`s, and hears a click on one of their actions through `barAction`, with the change, the bar and the action.
7
8
  It draws on `@noldova/code.editor.angular`'s code view through its public decorations, and is styled only with the interface kit's tokens.
8
9
 
9
10
  ## The worker
10
11
 
11
- `DiffWorker.create()` starts a worker that runs the default algorithm's line diff, as a `WorkerRunner` to give to `DocumentDiff`.
12
- In the browser that worker is the default path, so the page never waits for a diff; the app's build sets `webWorkerTsConfig` to bundle `diff.worker.ts`, as this package's `angular.json` does with `tsconfig.worker.json`.
13
- Without a worker the diff runs a slice at a time on the page, and its one call to the algorithm holds the page for its whole time, as `@noldova/code.editor.diff`'s README says.
12
+ An app gives the diff its own worker in two lines, because an app's build bundles a worker only from the app's own source, never from a package's built files.
13
+ Its worker file, `src/app/diff.worker.ts`, serves the default algorithm's line diff:
14
+
15
+ ```ts
16
+ import { DiffWorkerHost } from "@noldova/code.editor.diff";
17
+
18
+ DiffWorkerHost.serve(self);
19
+ ```
20
+
21
+ Its config starts that file with `DiffWorker.provide`, and its build sets `webWorkerTsConfig` to a tsconfig that holds the worker file, as this package's `angular.json` does with `tsconfig.worker.json`:
22
+
23
+ ```ts
24
+ export const appConfig: ApplicationConfig = {
25
+ providers: [DiffWorker.provide(() => new Worker(new URL("./diff.worker", import.meta.url), { type: "module" }))]
26
+ };
27
+ ```
28
+
29
+ A component then gives `inject(DiffWorker).runner` to `DocumentDiff`, one runner the app shares, whose worker ends with the app.
30
+ In the browser that worker is the default path, so the page never waits for a diff.
31
+ Without one the diff runs a slice at a time on the page, and its one call to the algorithm holds the page for its whole time, as `@noldova/code.editor.diff`'s README says; so the console warns once when no worker was provided, or when the worker fails, and says what to do.
32
+ On the server the runner runs on the page and warns nothing.
33
+ `DiffWorker.create()` still starts the package's own worker, which works only where the package's source is built, as in its tests, and warns once when it fails.
14
34
 
15
35
  [documents/ARCHITECTURE.md](../../documents/ARCHITECTURE.md) says how the view is built.
package/api/index.d.ts CHANGED
@@ -7,7 +7,10 @@
7
7
  */
8
8
  export { DiffEditorComponent } from "../app/components/diff-editor/diff-editor.component.js";
9
9
  export { DiffLayout } from "../app/enums/diff-layout.js";
10
+ export type { IDiffBars } from "../app/interfaces/i-diff-bars.js";
10
11
  export type { IDiffNavigator } from "../app/interfaces/i-diff-navigator.js";
12
+ export { DiffBar } from "../app/models/diff-bar.js";
13
+ export { DiffBarActionEvent } from "../app/models/diff-bar-action-event.js";
11
14
  export { DiffEditorClasses } from "../app/services/diff-editor-classes.js";
12
15
  export { DiffEditorCommands } from "../app/services/diff-editor-commands.js";
13
16
  export { DiffEditorContribution } from "../app/services/diff-editor-contribution.js";
package/api/index.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  export { DiffEditorComponent } from "../app/components/diff-editor/diff-editor.component.js";
9
9
  export { DiffLayout } from "../app/enums/diff-layout.js";
10
+ export { DiffBar } from "../app/models/diff-bar.js";
11
+ export { DiffBarActionEvent } from "../app/models/diff-bar-action-event.js";
10
12
  export { DiffEditorClasses } from "../app/services/diff-editor-classes.js";
11
13
  export { DiffEditorCommands } from "../app/services/diff-editor-commands.js";
12
14
  export { DiffEditorContribution } from "../app/services/diff-editor-contribution.js";
@@ -8,11 +8,13 @@
8
8
  import "@noldova/context.core";
9
9
  import { type InputSignal, type OutputEmitterRef, type Signal, type WritableSignal } from "@angular/core";
10
10
  import { type ILanguageDefinition, TextSelection, UndoHistory } from "@noldova/code.editor";
11
- import { type CodeFold, type ICodeDecorations } from "@noldova/code.editor.angular";
11
+ import { type CodeBarActionEvent, type CodeFold, type ICodeDecorations } from "@noldova/code.editor.angular";
12
12
  import { type DocumentDiff } from "@noldova/code.editor.diff";
13
13
  import { type IReadOnlyList } from "@noldova/context.collections";
14
14
  import { DiffLayout } from "../../enums/diff-layout.js";
15
+ import type { IDiffBars } from "../../interfaces/i-diff-bars.js";
15
16
  import type { IDiffNavigator } from "../../interfaces/i-diff-navigator.js";
17
+ import type { DiffBarActionEvent } from "../../models/diff-bar-action-event.js";
16
18
  import { DiffFolds } from "../../models/diff-folds.js";
17
19
  import * as i0 from "@angular/core";
18
20
  /**
@@ -42,6 +44,7 @@ export declare class DiffEditorComponent implements IDiffNavigator {
42
44
  private readonly originalCache;
43
45
  private readonly opened;
44
46
  private readonly width;
47
+ private originalTicker;
45
48
  /**
46
49
  * The diff of the two documents, which the view follows through every
47
50
  * edit; required.
@@ -83,6 +86,17 @@ export declare class DiffEditorComponent implements IDiffNavigator {
83
86
  * Whether the original side refuses edits; true when not bound.
84
87
  */
85
88
  readonly originalReadOnly: InputSignal<boolean>;
89
+ /**
90
+ * The bars of each change, or null, when not bound, for none: side by
91
+ * side, each bar is drawn above its change's first line on its side, and
92
+ * the other side gets a blank row so the two stay aligned; inline, every
93
+ * bar is drawn above the change.
94
+ */
95
+ readonly bars: InputSignal<IDiffBars | null>;
96
+ /**
97
+ * Emits a click on an action of a bar from {@link bars}, with its change.
98
+ */
99
+ readonly barAction: OutputEmitterRef<DiffBarActionEvent>;
86
100
  /**
87
101
  * Emits the chords of a key sequence the view or one of its panes waits to
88
102
  * complete, as the platform shows them, and null once it completes or
@@ -96,17 +110,19 @@ export declare class DiffEditorComponent implements IDiffNavigator {
96
110
  readonly inline: Signal<boolean>;
97
111
  protected readonly originalUndo: Signal<UndoHistory>;
98
112
  protected readonly folds: Signal<DiffFolds>;
113
+ private readonly barRows;
99
114
  protected readonly originalDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
100
115
  protected readonly modifiedDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
101
116
  protected readonly inlineDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
102
117
  protected readonly announcement: WritableSignal<string>;
118
+ private readonly originalHighlightEnd;
103
119
  /**
104
120
  * Creates the view, which Angular does for each `noldova-diff-editor`
105
121
  * element.
106
122
  *
107
123
  * @example
108
124
  * ```ts
109
- * import { Component } from "@angular/core";
125
+ * import { Component, inject } from "@angular/core";
110
126
  * import { TextDocument, UndoHistory } from "@noldova/code.editor";
111
127
  * import { DocumentDiff } from "@noldova/code.editor.diff";
112
128
  * import { DiffEditorComponent, DiffWorker } from "@noldova/code.editor.diff.angular";
@@ -117,7 +133,7 @@ export declare class DiffEditorComponent implements IDiffNavigator {
117
133
  * template: "<noldova-diff-editor [diff]=\"diff\" [history]=\"history\" originalLabel=\"main\" modifiedLabel=\"Working tree\" />"
118
134
  * })
119
135
  * export class ChangesComponent {
120
- * protected readonly diff: DocumentDiff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, DiffWorker.create());
136
+ * protected readonly diff: DocumentDiff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, inject(DiffWorker).runner);
121
137
  * protected readonly history: UndoHistory = new UndoHistory(this.diff.modified);
122
138
  * }
123
139
  * ```
@@ -151,6 +167,7 @@ export declare class DiffEditorComponent implements IDiffNavigator {
151
167
  * ```
152
168
  */
153
169
  previousChange(): boolean;
170
+ protected onBarAction(event: CodeBarActionEvent): void;
154
171
  protected toggle(fold: CodeFold): void;
155
172
  protected reveal(folds: IReadOnlyList<CodeFold>, selections: IReadOnlyList<TextSelection>): void;
156
173
  private onOriginalTokens;
@@ -159,7 +176,8 @@ export declare class DiffEditorComponent implements IDiffNavigator {
159
176
  private contextAt;
160
177
  private moveToChange;
161
178
  private static toggled;
179
+ private static originalLineAt;
162
180
  private static remPixels;
163
181
  static ɵfac: i0.ɵɵFactoryDeclaration<DiffEditorComponent, never>;
164
- static ɵcmp: i0.ɵɵComponentDeclaration<DiffEditorComponent, "noldova-diff-editor", never, { "diff": { "alias": "diff"; "required": true; "isSignal": true; }; "history": { "alias": "history"; "required": true; "isSignal": true; }; "originalHistory": { "alias": "originalHistory"; "required": false; "isSignal": true; }; "language": { "alias": "language"; "required": false; "isSignal": true; }; "layout": { "alias": "layout"; "required": false; "isSignal": true; }; "originalLabel": { "alias": "originalLabel"; "required": true; "isSignal": true; }; "modifiedLabel": { "alias": "modifiedLabel"; "required": true; "isSignal": true; }; "readOnly": { "alias": "readOnly"; "required": false; "isSignal": true; }; "originalReadOnly": { "alias": "originalReadOnly"; "required": false; "isSignal": true; }; }, { "keySequencePending": "keySequencePending"; }, never, never, true, never>;
182
+ static ɵcmp: i0.ɵɵComponentDeclaration<DiffEditorComponent, "noldova-diff-editor", never, { "diff": { "alias": "diff"; "required": true; "isSignal": true; }; "history": { "alias": "history"; "required": true; "isSignal": true; }; "originalHistory": { "alias": "originalHistory"; "required": false; "isSignal": true; }; "language": { "alias": "language"; "required": false; "isSignal": true; }; "layout": { "alias": "layout"; "required": false; "isSignal": true; }; "originalLabel": { "alias": "originalLabel"; "required": true; "isSignal": true; }; "modifiedLabel": { "alias": "modifiedLabel"; "required": true; "isSignal": true; }; "readOnly": { "alias": "readOnly"; "required": false; "isSignal": true; }; "originalReadOnly": { "alias": "originalReadOnly"; "required": false; "isSignal": true; }; "bars": { "alias": "bars"; "required": false; "isSignal": true; }; }, { "barAction": "barAction"; "keySequencePending": "keySequencePending"; }, never, never, true, never>;
165
183
  }
@@ -6,13 +6,14 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  import "@noldova/context.core";
9
- import { Component, computed, DestroyRef, effect, ElementRef, inject, input, output, signal, viewChild } from "@angular/core";
9
+ import { afterRenderEffect, Component, computed, DestroyRef, effect, ElementRef, inject, input, output, signal, untracked, viewChild } from "@angular/core";
10
10
  import { CommandContext, ConditionValues, EditorFeatureSet, EditorRegistries, KeyDispatchResult, KeyPress, TextPosition, TextSelection, TokenCache, UndoHistory } from "@noldova/code.editor";
11
11
  import { BackgroundTicker, CodeEditorComponent, CodeEmbeddedLines, KeyScope, LanguageTokenizer } from "@noldova/code.editor.angular";
12
12
  import { DiffSide } from "@noldova/code.editor.diff";
13
13
  import { HashSet, List } from "@noldova/context.collections";
14
14
  import { Resources } from "../../../resources.js";
15
15
  import { DiffLayout } from "../../enums/diff-layout.js";
16
+ import { DiffBarRows } from "../../models/diff-bar-rows.js";
16
17
  import { DiffFolds } from "../../models/diff-folds.js";
17
18
  import { DiffLayer } from "../../models/diff-layer.js";
18
19
  import { InlineNumbering } from "../../models/inline-numbering.js";
@@ -39,6 +40,7 @@ export class DiffEditorComponent {
39
40
  ...(ngDevMode ? [{ debugName: "opened" }] : /* istanbul ignore next */ []));
40
41
  width = signal(Number.POSITIVE_INFINITY, /* @ts-ignore */
41
42
  ...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
43
+ originalTicker = null;
42
44
  diff = input.required(/* @ts-ignore */
43
45
  ...(ngDevMode ? [{ debugName: "diff" }] : /* istanbul ignore next */ []));
44
46
  history = input.required(/* @ts-ignore */
@@ -57,6 +59,9 @@ export class DiffEditorComponent {
57
59
  ...(ngDevMode ? [{ debugName: "readOnly" }] : /* istanbul ignore next */ []));
58
60
  originalReadOnly = input(true, /* @ts-ignore */
59
61
  ...(ngDevMode ? [{ debugName: "originalReadOnly" }] : /* istanbul ignore next */ []));
62
+ bars = input(null, /* @ts-ignore */
63
+ ...(ngDevMode ? [{ debugName: "bars" }] : /* istanbul ignore next */ []));
64
+ barAction = output();
60
65
  keySequencePending = output();
61
66
  tokenizer = LanguageTokenizer.of(this.language);
62
67
  inline = computed(() => this.layout() === DiffLayout.Inline ||
@@ -70,14 +75,19 @@ export class DiffEditorComponent {
70
75
  return new DiffFolds(this.diff().unchangedRegions(contextLines, this.setting(DiffEditorSettings.minimumHiddenLines)), this.opened());
71
76
  }, /* @ts-ignore */
72
77
  ...(ngDevMode ? [{ debugName: "folds" }] : /* istanbul ignore next */ []));
78
+ barRows = computed(() => {
79
+ this.version();
80
+ return new DiffBarRows(this.diff(), this.bars());
81
+ }, /* @ts-ignore */
82
+ ...(ngDevMode ? [{ debugName: "barRows" }] : /* istanbul ignore next */ []));
73
83
  originalDecorations = computed(() => {
74
84
  this.version();
75
- return new List([new DiffLayer(this.diff(), DiffSide.Original)]);
85
+ return new List([this.barRows().sideOf(DiffSide.Original), new DiffLayer(this.diff(), DiffSide.Original)]);
76
86
  }, /* @ts-ignore */
77
87
  ...(ngDevMode ? [{ debugName: "originalDecorations" }] : /* istanbul ignore next */ []));
78
88
  modifiedDecorations = computed(() => {
79
89
  this.version();
80
- return new List([new DiffLayer(this.diff(), DiffSide.Modified)]);
90
+ return new List([this.barRows().sideOf(DiffSide.Modified), new DiffLayer(this.diff(), DiffSide.Modified)]);
81
91
  }, /* @ts-ignore */
82
92
  ...(ngDevMode ? [{ debugName: "modifiedDecorations" }] : /* istanbul ignore next */ []));
83
93
  inlineDecorations = computed(() => {
@@ -88,11 +98,17 @@ export class DiffEditorComponent {
88
98
  .where(t => t.originalLength > 0)
89
99
  .select((t) => new CodeEmbeddedLines(t.modifiedStart, diff.original, t.originalStart, t.originalLength, this.originalCache(), removed))
90
100
  .toList();
91
- return new List([new DiffLayer(diff, DiffSide.Modified, rows, new InlineNumbering(diff))]);
101
+ return new List([this.barRows().inline(), new DiffLayer(diff, DiffSide.Modified, rows, new InlineNumbering(diff))]);
92
102
  }, /* @ts-ignore */
93
103
  ...(ngDevMode ? [{ debugName: "inlineDecorations" }] : /* istanbul ignore next */ []));
94
104
  announcement = signal(Resources.empty, /* @ts-ignore */
95
105
  ...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
106
+ originalHighlightEnd = computed(() => {
107
+ this.version();
108
+ const view = this.modifiedView();
109
+ return DiffEditorComponent.originalLineAt(this.diff(), view.viewEnd()) + view.viewEndRows() + Resources.highlightAheadLines;
110
+ }, /* @ts-ignore */
111
+ ...(ngDevMode ? [{ debugName: "originalHighlightEnd" }] : /* istanbul ignore next */ []));
96
112
  constructor() {
97
113
  this.conditions.set(DiffEditorFeatures.inDiffEditor, true);
98
114
  this.features.provide(DiffEditorFeatures.navigator, this);
@@ -109,16 +125,22 @@ export class DiffEditorComponent {
109
125
  const cache = Object.isNull(tokenizer) ? null : new TokenCache(original, tokenizer);
110
126
  const ticker = Object.isNull(cache) ? null : new BackgroundTicker(original, hasTime => {
111
127
  const from = cache.validLineCount;
112
- const more = cache.advance(hasTime);
128
+ const more = cache.advance(hasTime, untracked(this.originalHighlightEnd));
113
129
  this.onOriginalTokens(from, cache.validLineCount);
114
130
  return more;
115
131
  });
116
132
  this.originalCache.set(cache);
133
+ this.originalTicker = ticker;
117
134
  onCleanup(() => {
135
+ this.originalTicker = null;
118
136
  ticker?.[Symbol.dispose]();
119
137
  cache?.[Symbol.dispose]();
120
138
  });
121
139
  });
140
+ afterRenderEffect(() => {
141
+ this.originalHighlightEnd();
142
+ untracked(() => this.originalTicker?.resume());
143
+ });
122
144
  const host = inject(ElementRef).nativeElement;
123
145
  const listener = event => this.onKeyDown(event);
124
146
  const observer = new ResizeObserver(entries => {
@@ -139,6 +161,9 @@ export class DiffEditorComponent {
139
161
  previousChange() {
140
162
  return this.moveToChange(false);
141
163
  }
164
+ onBarAction(event) {
165
+ this.barAction.emit(DiffBarRows.eventOf(event));
166
+ }
142
167
  toggle(fold) {
143
168
  const key = this.folds().keyOf(fold);
144
169
  this.opened.update(t => DiffEditorComponent.toggled(t, key, fold.collapsed));
@@ -197,16 +222,22 @@ export class DiffEditorComponent {
197
222
  next.remove(key);
198
223
  return next;
199
224
  }
225
+ static originalLineAt(diff, line) {
226
+ const change = diff.changes.lastOrDefault(t => t.modifiedStart < line);
227
+ if (Object.isUndefined(change))
228
+ return line;
229
+ return line < change.modifiedEnd ? change.originalEnd : line - change.modifiedEnd + change.originalEnd;
230
+ }
200
231
  static remPixels() {
201
232
  return Number.parseFloat(getComputedStyle(document.documentElement).fontSize);
202
233
  }
203
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
204
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: DiffEditorComponent, isStandalone: true, selector: "noldova-diff-editor", inputs: { diff: { classPropertyName: "diff", publicName: "diff", isSignal: true, isRequired: true, transformFunction: null }, history: { classPropertyName: "history", publicName: "history", isSignal: true, isRequired: true, transformFunction: null }, originalHistory: { classPropertyName: "originalHistory", publicName: "originalHistory", isSignal: true, isRequired: false, transformFunction: null }, language: { classPropertyName: "language", publicName: "language", isSignal: true, isRequired: false, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: false, transformFunction: null }, originalLabel: { classPropertyName: "originalLabel", publicName: "originalLabel", isSignal: true, isRequired: true, transformFunction: null }, modifiedLabel: { classPropertyName: "modifiedLabel", publicName: "modifiedLabel", isSignal: true, isRequired: true, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, originalReadOnly: { classPropertyName: "originalReadOnly", publicName: "originalReadOnly", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { keySequencePending: "keySequencePending" }, host: { properties: { "class.nol-diff-editor-inline": "inline()" }, classAttribute: "nol-diff-editor" }, providers: [KeyScope], viewQueries: [{ propertyName: "originalView", first: true, predicate: ["original"], descendants: true, isSignal: true }, { propertyName: "modifiedView", first: true, predicate: ["modified"], descendants: true, isSignal: true }], ngImport: i0, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"], dependencies: [{ kind: "component", type: CodeEditorComponent, selector: "noldova-code-editor", inputs: ["document", "history", "language", "label", "readOnly", "tabIndents", "decorations", "folds"], outputs: ["selectionsChange", "scrollChange", "foldToggle", "barAction", "keySequencePending"] }] });
234
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffEditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
235
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.2", type: DiffEditorComponent, isStandalone: true, selector: "noldova-diff-editor", inputs: { diff: { classPropertyName: "diff", publicName: "diff", isSignal: true, isRequired: true, transformFunction: null }, history: { classPropertyName: "history", publicName: "history", isSignal: true, isRequired: true, transformFunction: null }, originalHistory: { classPropertyName: "originalHistory", publicName: "originalHistory", isSignal: true, isRequired: false, transformFunction: null }, language: { classPropertyName: "language", publicName: "language", isSignal: true, isRequired: false, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: false, transformFunction: null }, originalLabel: { classPropertyName: "originalLabel", publicName: "originalLabel", isSignal: true, isRequired: true, transformFunction: null }, modifiedLabel: { classPropertyName: "modifiedLabel", publicName: "modifiedLabel", isSignal: true, isRequired: true, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, originalReadOnly: { classPropertyName: "originalReadOnly", publicName: "originalReadOnly", isSignal: true, isRequired: false, transformFunction: null }, bars: { classPropertyName: "bars", publicName: "bars", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { barAction: "barAction", keySequencePending: "keySequencePending" }, host: { properties: { "class.nol-diff-editor-inline": "inline()" }, classAttribute: "nol-diff-editor" }, providers: [KeyScope], viewQueries: [{ propertyName: "originalView", first: true, predicate: ["original"], descendants: true, isSignal: true }, { propertyName: "modifiedView", first: true, predicate: ["modified"], descendants: true, isSignal: true }], ngImport: i0, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"], dependencies: [{ kind: "component", type: CodeEditorComponent, selector: "noldova-code-editor", inputs: ["document", "history", "language", "label", "readOnly", "tabIndents", "decorations", "folds", "textOnly"], outputs: ["selectionsChange", "scrollChange", "foldToggle", "barAction", "keySequencePending"] }] });
205
236
  }
206
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorComponent, decorators: [{
237
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffEditorComponent, decorators: [{
207
238
  type: Component,
208
239
  args: [{ selector: "noldova-diff-editor", imports: [CodeEditorComponent], providers: [KeyScope], host: {
209
240
  "class": Resources.hostClass,
210
241
  [Resources.inlineClassBinding]: "inline()"
211
- }, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"] }]
212
- }], ctorParameters: () => [], propDecorators: { originalView: [{ type: i0.ViewChild, args: ["original", { isSignal: true }] }], modifiedView: [{ type: i0.ViewChild, args: ["modified", { isSignal: true }] }], diff: [{ type: i0.Input, args: [{ isSignal: true, alias: "diff", required: true }] }], history: [{ type: i0.Input, args: [{ isSignal: true, alias: "history", required: true }] }], originalHistory: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalHistory", required: false }] }], language: [{ type: i0.Input, args: [{ isSignal: true, alias: "language", required: false }] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: false }] }], originalLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalLabel", required: true }] }], modifiedLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "modifiedLabel", required: true }] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], originalReadOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalReadOnly", required: false }] }], keySequencePending: [{ type: i0.Output, args: ["keySequencePending"] }] } });
242
+ }, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (barAction)=\"onBarAction($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"] }]
243
+ }], ctorParameters: () => [], propDecorators: { originalView: [{ type: i0.ViewChild, args: ["original", { isSignal: true }] }], modifiedView: [{ type: i0.ViewChild, args: ["modified", { isSignal: true }] }], diff: [{ type: i0.Input, args: [{ isSignal: true, alias: "diff", required: true }] }], history: [{ type: i0.Input, args: [{ isSignal: true, alias: "history", required: true }] }], originalHistory: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalHistory", required: false }] }], language: [{ type: i0.Input, args: [{ isSignal: true, alias: "language", required: false }] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: false }] }], originalLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalLabel", required: true }] }], modifiedLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "modifiedLabel", required: true }] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], originalReadOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalReadOnly", required: false }] }], bars: [{ type: i0.Input, args: [{ isSignal: true, alias: "bars", required: false }] }], barAction: [{ type: i0.Output, args: ["barAction"] }], keySequencePending: [{ type: i0.Output, args: ["keySequencePending"] }] } });
@@ -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
+ import type { LineChange } from "@noldova/code.editor.diff";
9
+ import type { IReadOnlyList } from "@noldova/context.collections";
10
+ import type { DiffBar } from "../models/diff-bar.js";
11
+ /**
12
+ * Gives the diff view the bars of each change; the view asks again each time
13
+ * the diff changes.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { CodeBarAction } from "@noldova/code.editor.angular";
18
+ * import { DiffSide, type LineChange } from "@noldova/code.editor.diff";
19
+ * import { DiffBar, type IDiffBars } from "@noldova/code.editor.diff.angular";
20
+ * import { type IReadOnlyList, List } from "@noldova/context.collections";
21
+ *
22
+ * const bars: IDiffBars = {
23
+ * barsOf: (change: LineChange): IReadOnlyList<DiffBar> => new List([new DiffBar(DiffSide.Modified, `Change ${change.index + 1}`, null,
24
+ * new List([new CodeBarAction("keep", "Keep")]))])
25
+ * };
26
+ * ```
27
+ */
28
+ export interface IDiffBars {
29
+ /**
30
+ * The bars of a change, in the order the view draws them.
31
+ *
32
+ * @param change The change.
33
+ * @returns The change's bars, none for a change without a bar.
34
+ */
35
+ barsOf(change: LineChange): IReadOnlyList<DiffBar>;
36
+ }
@@ -0,0 +1,7 @@
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
+ */
@@ -0,0 +1,17 @@
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 { LineChange } from "@noldova/code.editor.diff";
9
+ import type { DiffBar } from "./diff-bar.js";
10
+ import { PlacedBar } from "./placed-bar.js";
11
+ export declare class ChangeBar {
12
+ readonly id: string;
13
+ readonly change: LineChange;
14
+ readonly bar: DiffBar;
15
+ constructor(id: string, change: LineChange, bar: DiffBar);
16
+ placedAt(line: number): PlacedBar;
17
+ }
@@ -0,0 +1,21 @@
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 { PlacedBar } from "./placed-bar.js";
9
+ export class ChangeBar {
10
+ id;
11
+ change;
12
+ bar;
13
+ constructor(id, change, bar) {
14
+ this.id = id;
15
+ this.change = change;
16
+ this.bar = bar;
17
+ }
18
+ placedAt(line) {
19
+ return new PlacedBar(this.id, line, this.change, this.bar);
20
+ }
21
+ }
@@ -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 { CodeBarAction } from "@noldova/code.editor.angular";
9
+ import type { LineChange } from "@noldova/code.editor.diff";
10
+ import type { DiffBar } from "./diff-bar.js";
11
+ /**
12
+ * A click on a {@link DiffBar}'s action, which the diff view emits as
13
+ * {@link DiffEditorComponent.barAction}.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import type { DiffBarActionEvent } from "@noldova/code.editor.diff.angular";
18
+ *
19
+ * declare const event: DiffBarActionEvent;
20
+ * console.log(event.action.id, event.change.index);
21
+ * ```
22
+ */
23
+ export declare class DiffBarActionEvent {
24
+ /**
25
+ * The change the bar is at, as the diff had it when the bar was drawn.
26
+ */
27
+ readonly change: LineChange;
28
+ /**
29
+ * The bar the host gave.
30
+ */
31
+ readonly bar: DiffBar;
32
+ /**
33
+ * The action clicked.
34
+ */
35
+ readonly action: CodeBarAction;
36
+ /**
37
+ * Creates the event.
38
+ *
39
+ * @param change The change the bar is at.
40
+ * @param bar The bar.
41
+ * @param action The action clicked.
42
+ */
43
+ constructor(change: LineChange, bar: DiffBar, action: CodeBarAction);
44
+ }
@@ -0,0 +1,17 @@
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
+ export class DiffBarActionEvent {
9
+ change;
10
+ bar;
11
+ action;
12
+ constructor(change, bar, action) {
13
+ this.change = change;
14
+ this.bar = bar;
15
+ this.action = action;
16
+ }
17
+ }
@@ -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 { type CodeBarActionEvent, type ICodeDecorations } from "@noldova/code.editor.angular";
9
+ import type { DiffSide, DocumentDiff } from "@noldova/code.editor.diff";
10
+ import type { IDiffBars } from "../interfaces/i-diff-bars.js";
11
+ import { DiffBarActionEvent } from "./diff-bar-action-event.js";
12
+ export declare class DiffBarRows {
13
+ private readonly bars;
14
+ constructor(diff: DocumentDiff, bars: IDiffBars | null);
15
+ sideOf(side: DiffSide): ICodeDecorations;
16
+ inline(): ICodeDecorations;
17
+ static eventOf(event: CodeBarActionEvent): DiffBarActionEvent;
18
+ }
@@ -0,0 +1,41 @@
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 { CodeDecorations, CodeSpacer } from "@noldova/code.editor.angular";
9
+ import { List } from "@noldova/context.collections";
10
+ import { ArgumentException } from "@noldova/context.exceptions";
11
+ import { Resources } from "../../resources.js";
12
+ import { ChangeBar } from "./change-bar.js";
13
+ import { DiffBarActionEvent } from "./diff-bar-action-event.js";
14
+ import { PlacedBar } from "./placed-bar.js";
15
+ export class DiffBarRows {
16
+ bars;
17
+ constructor(diff, bars) {
18
+ this.bars = Object.isNull(bars) ? new List()
19
+ : diff.changes.selectMany(change => bars.barsOf(change).select((bar, index) => new ChangeBar(`${change.index}:${index}`, change, bar))).toList();
20
+ }
21
+ sideOf(side) {
22
+ const rows = new List();
23
+ for (const group of this.bars.groupBy(t => t.change)) {
24
+ const change = group.key;
25
+ const own = group.where(t => t.bar.side === side).toList();
26
+ rows.addRange(own.select(t => t.placedAt(change.startOf(side))));
27
+ const missing = group.count(t => t.bar.side !== side) - own.count();
28
+ if (missing > 0)
29
+ rows.add(new CodeSpacer(change.startOf(side), missing));
30
+ }
31
+ return new CodeDecorations(undefined, undefined, undefined, rows);
32
+ }
33
+ inline() {
34
+ return new CodeDecorations(undefined, undefined, undefined, this.bars.select((t) => t.placedAt(t.change.modifiedStart)).toList());
35
+ }
36
+ static eventOf(event) {
37
+ if (!(event.bar instanceof PlacedBar))
38
+ throw new ArgumentException(Resources.formatForeignBar(event.bar.id), Resources.eventParameter);
39
+ return new DiffBarActionEvent(event.bar.change, event.bar.diffBar, event.action);
40
+ }
41
+ }
@@ -0,0 +1,64 @@
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 { CodeBarAction } from "@noldova/code.editor.angular";
9
+ import type { DiffSide } from "@noldova/code.editor.diff";
10
+ import type { IReadOnlyList } from "@noldova/context.collections";
11
+ /**
12
+ * A bar the diff view draws at a change, on one side, with its note and its
13
+ * own actions, such as a host's actions for that change.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { CodeBarAction } from "@noldova/code.editor.angular";
18
+ * import { DiffSide } from "@noldova/code.editor.diff";
19
+ * import { DiffBar } from "@noldova/code.editor.diff.angular";
20
+ * import { List } from "@noldova/context.collections";
21
+ *
22
+ * const bar = new DiffBar(DiffSide.Modified, "Change", null, new List([new CodeBarAction("keep", "Keep")]));
23
+ * ```
24
+ */
25
+ export declare class DiffBar {
26
+ /**
27
+ * The side the bar is drawn on; the inline layout draws every bar above
28
+ * the change.
29
+ */
30
+ readonly side: DiffSide;
31
+ /**
32
+ * The text at the bar's start.
33
+ */
34
+ readonly note: string;
35
+ /**
36
+ * The kit icon's name before the note, or null for none.
37
+ */
38
+ readonly icon: string | null;
39
+ /**
40
+ * The bar's buttons, in order.
41
+ */
42
+ readonly actions: IReadOnlyList<CodeBarAction>;
43
+ /**
44
+ * The bar's background, or null for the code view's bar background.
45
+ */
46
+ readonly background: string | null;
47
+ /**
48
+ * The bar's text color, or null for the code view's bar color.
49
+ */
50
+ readonly color: string | null;
51
+ /**
52
+ * Creates a bar.
53
+ *
54
+ * @param side The side the bar is drawn on.
55
+ * @param note The text at the bar's start.
56
+ * @param icon The kit icon's name before the note, or null for none.
57
+ * @param actions The bar's buttons, in order.
58
+ * @param background The bar's background, or null, when not given, for
59
+ * the code view's bar background.
60
+ * @param color The bar's text color, or null, when not given, for the code
61
+ * view's bar color.
62
+ */
63
+ constructor(side: DiffSide, note: string, icon: string | null, actions: IReadOnlyList<CodeBarAction>, background?: string | null, color?: string | null);
64
+ }
@@ -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
+ export class DiffBar {
9
+ side;
10
+ note;
11
+ icon;
12
+ actions;
13
+ background;
14
+ color;
15
+ constructor(side, note, icon, actions, background = null, color = null) {
16
+ this.side = side;
17
+ this.note = note;
18
+ this.icon = icon;
19
+ this.actions = actions;
20
+ this.background = background;
21
+ this.color = color;
22
+ }
23
+ }
@@ -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 { CodeBar } from "@noldova/code.editor.angular";
9
+ import type { LineChange } from "@noldova/code.editor.diff";
10
+ import type { DiffBar } from "./diff-bar.js";
11
+ export declare class PlacedBar extends CodeBar {
12
+ readonly change: LineChange;
13
+ readonly diffBar: DiffBar;
14
+ constructor(id: string, line: number, change: LineChange, bar: DiffBar);
15
+ }
@@ -0,0 +1,17 @@
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 { CodeBar } from "@noldova/code.editor.angular";
9
+ export class PlacedBar extends CodeBar {
10
+ change;
11
+ diffBar;
12
+ constructor(id, line, change, bar) {
13
+ super(id, line, bar.note, bar.icon, bar.actions, bar.background, bar.color);
14
+ this.change = change;
15
+ this.diffBar = bar;
16
+ }
17
+ }
@@ -16,10 +16,10 @@ export class DiffEditorRegistries {
16
16
  constructor() {
17
17
  this.registries.add(new DiffContribution(), new DiffEditorContribution());
18
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" });
19
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffEditorRegistries, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
20
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffEditorRegistries, providedIn: "root" });
21
21
  }
22
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorRegistries, decorators: [{
22
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffEditorRegistries, decorators: [{
23
23
  type: Injectable,
24
24
  args: [{ providedIn: "root" }]
25
25
  }], ctorParameters: () => [] });
@@ -1,34 +1,107 @@
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
- */
1
+ import { type EnvironmentProviders } from "@angular/core";
2
+ import { type IBackgroundRunner } from "@noldova/code.editor";
8
3
  import { WorkerRunner } from "@noldova/code.editor.angular";
4
+ import * as i0 from "@angular/core";
9
5
  /**
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.
6
+ * The runner a diff runs its line diff on in the browser: one worker for the
7
+ * app that serves the default algorithm's line diff job, so the page never
8
+ * waits for a diff.
12
9
  *
13
10
  * @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`.
11
+ * An app's build bundles a worker only from the app's own source, never from
12
+ * a package, so the app keeps a worker file whose only work is
13
+ * `DiffWorkerHost.serve(self)` from `@noldova/code.editor.diff`, and starts it
14
+ * through {@link DiffWorker.provide} with
15
+ * `new Worker(new URL(...), { type: "module" })` in its own source. Its
16
+ * build sets `webWorkerTsConfig` so that file is bundled as a worker.
17
+ * {@link DiffWorker.runner} is then a runner on that worker, ended when the
18
+ * app is destroyed; give it to every `DocumentDiff`.
19
+ *
20
+ * When no worker is provided, `runner` runs the diff a slice at a time on the
21
+ * page, and the console says so once; when the worker fails, as when its file
22
+ * isn't found, the console says so once and the diff runs on the page from
23
+ * then on. A diff on the page holds it for the algorithm's whole call, which
24
+ * on a large file is long. On the server, as when a page is prerendered, no
25
+ * worker starts and nothing is said. A host's own algorithm needs a worker of
26
+ * its own that serves its job; this worker runs it on the page instead.
18
27
  *
19
28
  * @example
20
29
  * ```ts
30
+ * // src/app/diff.worker.ts
31
+ * import { DiffWorkerHost } from "@noldova/code.editor.diff";
32
+ *
33
+ * DiffWorkerHost.serve(self);
34
+ * ```
35
+ *
36
+ * ```ts
37
+ * // src/app/app.config.ts
38
+ * import type { ApplicationConfig } from "@angular/core";
39
+ * import { DiffWorker } from "@noldova/code.editor.diff.angular";
40
+ *
41
+ * export const appConfig: ApplicationConfig = {
42
+ * providers: [DiffWorker.provide(() => new Worker(new URL("./diff.worker", import.meta.url), { type: "module" }))]
43
+ * };
44
+ * ```
45
+ *
46
+ * ```ts
47
+ * import { Component, inject } from "@angular/core";
21
48
  * import { TextDocument } from "@noldova/code.editor";
22
49
  * import { DocumentDiff } from "@noldova/code.editor.diff";
23
- * import { DiffWorker } from "@noldova/code.editor.diff.angular";
50
+ * import { DiffEditorComponent, DiffWorker } from "@noldova/code.editor.diff.angular";
24
51
  *
25
- * using runner = DiffWorker.create();
26
- * using diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, runner);
52
+ * @Component({
53
+ * selector: "app-changes",
54
+ * imports: [DiffEditorComponent],
55
+ * template: "<noldova-diff-editor [diff]=\"diff\" />"
56
+ * })
57
+ * export class ChangesComponent {
58
+ * protected readonly diff: DocumentDiff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, inject(DiffWorker).runner);
59
+ * }
27
60
  * ```
28
61
  */
29
62
  export declare class DiffWorker {
63
+ private static readonly start;
64
+ /**
65
+ * The app's diff runner: a worker runner on the provided worker in the
66
+ * browser, or a sliced runner on the page when none is provided or on the
67
+ * server.
68
+ */
69
+ readonly runner: IBackgroundRunner;
70
+ /**
71
+ * Creates the app's diff runner, starting the provided worker once in the
72
+ * browser; Angular creates it once per app and disposes of the worker with
73
+ * the app.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { inject } from "@angular/core";
78
+ * import { DiffWorker } from "@noldova/code.editor.diff.angular";
79
+ *
80
+ * const runner = inject(DiffWorker).runner;
81
+ * ```
82
+ */
83
+ constructor();
84
+ /**
85
+ * Gives the app its diff worker.
86
+ *
87
+ * @param start Starts the app's worker, whose file calls
88
+ * `DiffWorkerHost.serve(self)`; called once, when {@link DiffWorker.runner}
89
+ * is first needed in the browser.
90
+ * @returns The providers to add to the app's configuration.
91
+ * @example
92
+ * ```ts
93
+ * import { DiffWorker } from "@noldova/code.editor.diff.angular";
94
+ *
95
+ * const providers = [DiffWorker.provide(() => new Worker(new URL("./diff.worker", import.meta.url), { type: "module" }))];
96
+ * ```
97
+ */
98
+ static provide(start: () => Worker): EnvironmentProviders;
30
99
  /**
31
- * Starts a worker running the package's `diff.worker.ts`.
100
+ * Starts a worker running the package's own `diff.worker.ts`, which works
101
+ * only where that source is built, as in this package's tests; an app's
102
+ * build doesn't bundle it, so an app uses {@link DiffWorker.provide} and
103
+ * {@link DiffWorker.runner} instead. When the worker fails, the console
104
+ * says so once and the runner runs the diff on the page.
32
105
  *
33
106
  * @returns The runner; dispose it to end its worker.
34
107
  * @example
@@ -39,4 +112,7 @@ export declare class DiffWorker {
39
112
  * ```
40
113
  */
41
114
  static create(): WorkerRunner;
115
+ private static runnerOf;
116
+ static ɵfac: i0.ɵɵFactoryDeclaration<DiffWorker, never>;
117
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
42
118
  }
@@ -5,9 +5,42 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import { isPlatformBrowser } from "@angular/common";
9
+ import { DestroyRef, inject, Injectable, InjectionToken, makeEnvironmentProviders, PLATFORM_ID } from "@angular/core";
10
+ import { SlicedRunner } from "@noldova/code.editor";
8
11
  import { WorkerRunner } from "@noldova/code.editor.angular";
12
+ import { Resources } from "../../resources.js";
13
+ import * as i0 from "@angular/core";
9
14
  export class DiffWorker {
15
+ static start = new InjectionToken(Resources.workerStartToken, { providedIn: "root", factory: () => null });
16
+ runner;
17
+ constructor() {
18
+ const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
19
+ const start = inject(DiffWorker.start);
20
+ if (!isBrowser || Object.isNull(start)) {
21
+ if (isBrowser)
22
+ console.warn(Resources.workerMissingWarning);
23
+ this.runner = new SlicedRunner();
24
+ return;
25
+ }
26
+ const runner = DiffWorker.runnerOf(start());
27
+ inject(DestroyRef).onDestroy(() => runner[Symbol.dispose]());
28
+ this.runner = runner;
29
+ }
30
+ static provide(start) {
31
+ return makeEnvironmentProviders([{ provide: DiffWorker.start, useValue: start }]);
32
+ }
10
33
  static create() {
11
- return new WorkerRunner(new Worker(new URL("../workers/diff.worker.js", import.meta.url), { type: "module" }));
34
+ return DiffWorker.runnerOf(new Worker(new URL("../workers/diff.worker.js", import.meta.url), { type: "module" }));
35
+ }
36
+ static runnerOf(worker) {
37
+ worker.addEventListener(Resources.workerError, () => console.warn(Resources.workerFailedWarning), { once: true });
38
+ return new WorkerRunner(worker);
12
39
  }
40
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffWorker, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
41
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffWorker, providedIn: "root" });
13
42
  }
43
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DiffWorker, decorators: [{
44
+ type: Injectable,
45
+ args: [{ providedIn: "root" }]
46
+ }], ctorParameters: () => [] });
@@ -5,8 +5,5 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
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);
8
+ import { DiffWorkerHost } from "@noldova/code.editor.diff";
9
+ DiffWorkerHost.serve(self);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/code.editor.diff.angular",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
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
5
  "type": "module",
6
6
  "main": "api/index.js",
@@ -20,22 +20,23 @@
20
20
  "registry": "https://registry.npmjs.org/"
21
21
  },
22
22
  "scripts": {
23
+ "perf": "playwright install --only-shell chromium && ng run code-editor-diff:perf",
23
24
  "test": "ngc -p tsconfig.json && playwright install --only-shell chromium && ng test"
24
25
  },
25
26
  "dependencies": {
26
- "@noldova/code.editor": "0.0.2",
27
- "@noldova/code.editor.angular": "0.0.2",
28
- "@noldova/code.editor.diff": "0.0.2",
27
+ "@noldova/code.editor": "0.0.4",
28
+ "@noldova/code.editor.angular": "0.0.4",
29
+ "@noldova/code.editor.diff": "0.0.4",
29
30
  "tslib": "2.8.1"
30
31
  },
31
32
  "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.17 <0.1.0",
35
- "@noldova/context.core": ">=0.0.17 <0.1.0",
36
- "@noldova/context.exceptions": ">=0.0.17 <0.1.0",
37
- "@noldova/ui.components.angular": ">=0.0.35 <0.1.0",
33
+ "@angular/common": ">=22.3.2 <23.0.0",
34
+ "@angular/core": ">=22.3.2 <23.0.0",
35
+ "@noldova/context.collections": ">=0.0.20 <0.1.0",
36
+ "@noldova/context.core": ">=0.0.20 <0.1.0",
37
+ "@noldova/context.exceptions": ">=0.0.20 <0.1.0",
38
+ "@noldova/ui.components.angular": ">=0.0.57 <0.1.0",
38
39
  "rxjs": ">=7.8.2 <8.0.0"
39
40
  },
40
- "gitHead": "3d402fbe7f27ad6c31227bc0e9372fa06484a79f"
41
+ "gitHead": "89862a4b843a36b3b3c3cbb2f141ca7f68a04f30"
41
42
  }
package/resources.d.ts CHANGED
@@ -25,6 +25,10 @@ export declare class Resources {
25
25
  static readonly navigatorFeature: string;
26
26
  static readonly inDiffEditorCondition: string;
27
27
  static readonly inDiffEditorDescription: string;
28
+ static readonly workerError: "error";
29
+ static readonly workerStartToken: string;
30
+ static readonly workerFailedWarning: string;
31
+ static readonly workerMissingWarning: string;
28
32
  static readonly contextLinesDescription: string;
29
33
  static readonly minimumHiddenLinesDescription: string;
30
34
  static readonly characterDiffLimitDescription: string;
@@ -33,6 +37,7 @@ export declare class Resources {
33
37
  static readonly defaultMinimumHiddenLines: number;
34
38
  static readonly defaultCharacterDiffLimit: number;
35
39
  static readonly defaultInlineBreakpoint: number;
40
+ static readonly highlightAheadLines: number;
36
41
  static readonly contextLinesMinimum: number;
37
42
  static readonly minimumHiddenLinesMinimum: number;
38
43
  static readonly characterDiffLimitMinimum: number;
@@ -54,6 +59,8 @@ export declare class Resources {
54
59
  static readonly ofWord: string;
55
60
  static readonly removedWord: string;
56
61
  static readonly addedWord: string;
62
+ static readonly eventParameter: string;
63
+ static formatForeignBar(id: string): string;
57
64
  static formatChange(position: number, count: number, removed: number, added: number): string;
58
65
  private static words;
59
66
  private static linesWord;
package/resources.js CHANGED
@@ -26,6 +26,12 @@ export class Resources {
26
26
  static navigatorFeature = "diffNavigator";
27
27
  static inDiffEditorCondition = "inDiffEditor";
28
28
  static inDiffEditorDescription = "The focus is in a diff view.";
29
+ static workerError = "error";
30
+ static workerStartToken = "noldova.code.editor.diff.angular.workerStart";
31
+ static workerFailedWarning = "The diff worker failed, so diffs run on the page from now on and can hold it on large files. "
32
+ + "Give the app its own diff worker with DiffWorker.provide, as @noldova/code.editor.diff.angular's README says.";
33
+ static workerMissingWarning = "No diff worker was provided, so diffs run on the page and can hold it on large files. "
34
+ + "Give the app its own diff worker with DiffWorker.provide, as @noldova/code.editor.diff.angular's README says.";
29
35
  static contextLinesDescription = "The unchanged lines a diff view keeps next to each change.";
30
36
  static minimumHiddenLinesDescription = "The fewest unchanged lines a diff view folds away.";
31
37
  static characterDiffLimitDescription = "The most characters on both sides of a change that a diff compares character by character.";
@@ -34,6 +40,7 @@ export class Resources {
34
40
  static defaultMinimumHiddenLines = 3;
35
41
  static defaultCharacterDiffLimit = 20000;
36
42
  static defaultInlineBreakpoint = 50;
43
+ static highlightAheadLines = 1_000;
37
44
  static contextLinesMinimum = 0;
38
45
  static minimumHiddenLinesMinimum = 1;
39
46
  static characterDiffLimitMinimum = 0;
@@ -55,6 +62,10 @@ export class Resources {
55
62
  static ofWord = "of";
56
63
  static removedWord = "removed";
57
64
  static addedWord = "added";
65
+ static eventParameter = "event";
66
+ static formatForeignBar(id) {
67
+ return `The diff view didn't draw the bar "${id}", so it can't name the change it belongs to.`;
68
+ }
58
69
  static formatChange(position, count, removed, added) {
59
70
  const parts = new List();
60
71
  if (removed > 0)