@noldova/code.editor.merge.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Noldova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # @noldova/code.editor.merge.angular
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The code editor's merge view in Angular: `MergeEditorComponent`, the `noldova-merge-editor` 3-way merge view, with ours and theirs side by side over the result, each conflict's choices, and `ActiveConflict`, the conflict at the caret.
4
+ It draws its conflicts with `@noldova/code.editor.angular`'s public decorations, and every choice and edit goes through `@noldova/code.editor.merge`'s `MergeDocument`.
5
+ It is styled only with the interface kit's tokens, so the page that shows it loads the kit's `kit.css` and `theme.css`, as the tests' page does.
6
+
7
+ [documents/ARCHITECTURE.md](../../documents/ARCHITECTURE.md) says how the views are built.
package/api/index.d.ts ADDED
@@ -0,0 +1,10 @@
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 { ActiveConflict } from "../app/models/active-conflict.js";
9
+ export { ConflictChoice, ConflictState } from "@noldova/code.editor.merge";
10
+ export { MergeEditorComponent } from "../app/components/merge-editor/merge-editor.component.js";
package/api/index.js ADDED
@@ -0,0 +1,10 @@
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 { ActiveConflict } from "../app/models/active-conflict.js";
9
+ export { ConflictChoice, ConflictState } from "@noldova/code.editor.merge";
10
+ export { MergeEditorComponent } from "../app/components/merge-editor/merge-editor.component.js";
@@ -0,0 +1,407 @@
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 InputSignal, type OutputEmitterRef, type Signal, type WritableSignal } from "@angular/core";
10
+ import { type ILanguageDefinition, TextDocument, TextSelection, UndoHistory } from "@noldova/code.editor";
11
+ import { type CodeBarActionEvent, type CodeDecorations } from "@noldova/code.editor.angular";
12
+ import { ConflictChoice, ConflictMarkersException, ConflictState, MergeDocument } from "@noldova/code.editor.merge";
13
+ import { type IReadOnlyList } from "@noldova/context.collections";
14
+ import { ButtonSize, ButtonVariant } from "@noldova/ui.components.angular";
15
+ import { Resources } from "../../../resources.js";
16
+ import { ActiveConflict } from "../../models/active-conflict.js";
17
+ import { MergeOpening } from "../../models/merge-opening.js";
18
+ import * as i0 from "@angular/core";
19
+ /**
20
+ * The `noldova-merge-editor` component: the merge view, which shows ours and
21
+ * theirs read-only above an editable result, with the choices for each
22
+ * conflict.
23
+ *
24
+ * @remarks
25
+ * It draws its panes through the code view's decorations, and every choice
26
+ * and edit goes through a `MergeDocument`. Without `merged`, its 3-way merge
27
+ * finds the conflicts; with it, the
28
+ * conflicts are the ones its markers mark. When ours or theirs is null, the
29
+ * view shows the side that is left, read-only, with no result and no
30
+ * conflicts. Content marked `nolMergeOursHead`, `nolMergeTheirsHead` and
31
+ * `nolMergeResultHead` is projected at the top of its side and of the
32
+ * result. Alt with Down or Up moves between conflicts.
33
+ */
34
+ export declare class MergeEditorComponent {
35
+ private static readonly BAR_CHOICES;
36
+ private readonly resultView;
37
+ private readonly version;
38
+ private cleanText;
39
+ private reportedStates;
40
+ /**
41
+ * The base text, or null when the merge has no base, which reads as
42
+ * empty; required.
43
+ */
44
+ readonly base: InputSignal<string | null>;
45
+ /**
46
+ * Our side's text, or null when our side deleted the file; required.
47
+ */
48
+ readonly ours: InputSignal<string | null>;
49
+ /**
50
+ * Their side's text, or null when their side deleted the file; required.
51
+ */
52
+ readonly theirs: InputSignal<string | null>;
53
+ /**
54
+ * Git's merged file with its zdiff3 conflict markers, or null, when not
55
+ * bound, to merge the three texts here.
56
+ */
57
+ readonly merged: InputSignal<string | null>;
58
+ /**
59
+ * The language that colors every pane: its id in the app's code editor
60
+ * registries, its definition, or null, when not bound, for plain text; each
61
+ * pane shows its text plain until the language's tokenizer is ready.
62
+ */
63
+ readonly language: InputSignal<string | ILanguageDefinition | null>;
64
+ /**
65
+ * Our side's name, on its pane and in the choices; required.
66
+ */
67
+ readonly oursLabel: InputSignal<string>;
68
+ /**
69
+ * Their side's name, on its pane and in the choices; required.
70
+ */
71
+ readonly theirsLabel: InputSignal<string>;
72
+ /**
73
+ * Whether the result refuses edits and choices; false when not bound.
74
+ */
75
+ readonly readOnly: InputSignal<boolean>;
76
+ /**
77
+ * Whether the bar between the sides and the result shows, with its count
78
+ * of unresolved conflicts and the choices for the conflict with the caret;
79
+ * true when not bound.
80
+ */
81
+ readonly toolbar: InputSignal<boolean>;
82
+ /**
83
+ * Whether each side and the result are drawn as a card, `--nol-panel`
84
+ * with a `--nol-card-border` border and a `--nol-radius-large` corner;
85
+ * false when not bound.
86
+ */
87
+ readonly panels: InputSignal<boolean>;
88
+ /**
89
+ * Whether the base shows read-only between ours and theirs, with each
90
+ * conflict's base lines under a bar; false when not bound.
91
+ */
92
+ readonly showBase: InputSignal<boolean>;
93
+ /**
94
+ * Emits the result text after every change to it.
95
+ */
96
+ readonly resultChange: OutputEmitterRef<string>;
97
+ /**
98
+ * Emits the conflicts' states, in order, at the start and whenever they
99
+ * change.
100
+ */
101
+ readonly conflictsChange: OutputEmitterRef<IReadOnlyList<ConflictState>>;
102
+ /**
103
+ * Emits the index of the conflict with the caret, from 0, or null when
104
+ * the caret leaves every conflict.
105
+ */
106
+ readonly activeConflictChange: OutputEmitterRef<number | null>;
107
+ /**
108
+ * Emits the exception of a `merged` file whose markers don't parse; the
109
+ * view then shows the line that breaks them in place of the merge.
110
+ */
111
+ readonly markersFailed: OutputEmitterRef<ConflictMarkersException>;
112
+ /**
113
+ * Emits the chords of a key sequence the view or one of its panes waits to
114
+ * complete, as the platform shows them, and null once it completes or
115
+ * drops; the panes and the view's own keys share one dispatcher.
116
+ */
117
+ readonly keySequencePending: OutputEmitterRef<string | null>;
118
+ /**
119
+ * The conflict with the caret, or null when the caret is in none.
120
+ */
121
+ readonly activeConflict: Signal<ActiveConflict | null>;
122
+ protected readonly resources: typeof Resources;
123
+ protected readonly choices: typeof ConflictChoice;
124
+ protected readonly compact: ButtonSize;
125
+ protected readonly secondary: ButtonVariant;
126
+ protected readonly opening: Signal<MergeOpening>;
127
+ protected readonly active: WritableSignal<number | null>;
128
+ protected readonly announcement: WritableSignal<string>;
129
+ protected readonly oursDocument: Signal<TextDocument>;
130
+ protected readonly theirsDocument: Signal<TextDocument>;
131
+ protected readonly oursHistory: Signal<UndoHistory>;
132
+ protected readonly theirsHistory: Signal<UndoHistory>;
133
+ protected readonly oursLines: Signal<IReadOnlyList<number | null>>;
134
+ protected readonly theirsLines: Signal<IReadOnlyList<number | null>>;
135
+ protected readonly oursDecorations: Signal<IReadOnlyList<CodeDecorations>>;
136
+ protected readonly theirsDecorations: Signal<IReadOnlyList<CodeDecorations>>;
137
+ protected readonly baseDocument: Signal<TextDocument>;
138
+ protected readonly baseHistory: Signal<UndoHistory>;
139
+ protected readonly baseDecorations: Signal<IReadOnlyList<CodeDecorations>>;
140
+ protected readonly survivorIsOurs: Signal<boolean>;
141
+ protected readonly deletedNote: Signal<string>;
142
+ protected readonly states: Signal<IReadOnlyList<ConflictState>>;
143
+ protected readonly summary: Signal<string>;
144
+ protected readonly resultDecorations: Signal<IReadOnlyList<CodeDecorations>>;
145
+ protected readonly canChoose: Signal<boolean>;
146
+ /**
147
+ * Creates the view, which Angular does for each `noldova-merge-editor`
148
+ * element.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { Component } from "@angular/core";
153
+ * import { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
154
+ *
155
+ * @Component({
156
+ * selector: "app-merge",
157
+ * imports: [MergeEditorComponent],
158
+ * template: "<noldova-merge-editor [base]=\"base\" [ours]=\"ours\" [theirs]=\"theirs\" oursLabel=\"main\" theirsLabel=\"feature\" (resultChange)=\"result = $event\" />"
159
+ * })
160
+ * export class MergeComponent {
161
+ * protected readonly base: string = "a\n";
162
+ * protected readonly ours: string = "b\n";
163
+ * protected readonly theirs: string = "c\n";
164
+ * protected result: string = "";
165
+ * }
166
+ * ```
167
+ */
168
+ constructor();
169
+ /**
170
+ * Gives the result text.
171
+ *
172
+ * @returns The result, or null when a side deleted the file or the
173
+ * markers of `merged` don't parse.
174
+ * @example
175
+ * ```ts
176
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
177
+ *
178
+ * function resultOf(view: MergeEditorComponent): string {
179
+ * return view.result() ?? "";
180
+ * }
181
+ * ```
182
+ */
183
+ result(): string | null;
184
+ /**
185
+ * Counts the conflicts still unresolved.
186
+ *
187
+ * @returns The count; 0 when there is no result.
188
+ * @example
189
+ * ```ts
190
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
191
+ *
192
+ * function canSave(view: MergeEditorComponent): boolean {
193
+ * return view.unresolvedCount() === 0;
194
+ * }
195
+ * ```
196
+ */
197
+ unresolvedCount(): number;
198
+ /**
199
+ * Tells whether the result differs from the one at the last
200
+ * {@link MergeEditorComponent.markClean}, or from no result before it.
201
+ *
202
+ * @returns True while the result has unsaved changes.
203
+ * @example
204
+ * ```ts
205
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
206
+ *
207
+ * function shouldAskBeforeClosing(view: MergeEditorComponent): boolean {
208
+ * return view.dirty();
209
+ * }
210
+ * ```
211
+ */
212
+ dirty(): boolean;
213
+ /**
214
+ * Records the current result as saved, so
215
+ * {@link MergeEditorComponent.dirty} is false until it changes.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
220
+ *
221
+ * function saved(view: MergeEditorComponent): void {
222
+ * view.markClean();
223
+ * }
224
+ * ```
225
+ */
226
+ markClean(): void;
227
+ /**
228
+ * Accepts a choice for one conflict, replacing its text in the result as
229
+ * one undoable step; nothing happens when there is no result
230
+ * or the view is read-only.
231
+ *
232
+ * @param index The conflict's index, from 0.
233
+ * @param choice The side, or both sides in an order, to keep.
234
+ * @example
235
+ * ```ts
236
+ * import { ConflictChoice } from "@noldova/code.editor.merge";
237
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
238
+ *
239
+ * function takeOursForFirst(view: MergeEditorComponent): void {
240
+ * view.accept(0, ConflictChoice.Ours);
241
+ * }
242
+ * ```
243
+ */
244
+ accept(index: number, choice: ConflictChoice): void;
245
+ /**
246
+ * Accepts a choice for every unresolved conflict as one undoable step;
247
+ * nothing happens when there is no result
248
+ * or the view is read-only.
249
+ *
250
+ * @param choice The side, or both sides in an order, to keep.
251
+ * @example
252
+ * ```ts
253
+ * import { ConflictChoice } from "@noldova/code.editor.merge";
254
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
255
+ *
256
+ * function takeTheirsForAll(view: MergeEditorComponent): void {
257
+ * view.acceptAll(ConflictChoice.Theirs);
258
+ * }
259
+ * ```
260
+ */
261
+ acceptAll(choice: ConflictChoice): void;
262
+ /**
263
+ * Puts one conflict back to its base text, unresolved, as one undoable
264
+ * step; nothing happens when there is no result
265
+ * or the view is read-only.
266
+ *
267
+ * @param index The conflict's index, from 0.
268
+ * @example
269
+ * ```ts
270
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
271
+ *
272
+ * function reopenFirst(view: MergeEditorComponent): void {
273
+ * view.reset(0);
274
+ * }
275
+ * ```
276
+ */
277
+ reset(index: number): void;
278
+ /**
279
+ * Sets one conflict's text in the result as one undoable step and marks
280
+ * it suggested until the person edits it; nothing happens when there is
281
+ * no result or the view is read-only.
282
+ *
283
+ * @param index The conflict's index, from 0.
284
+ * @param text The conflict's new text.
285
+ * @example
286
+ * ```ts
287
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
288
+ *
289
+ * function suggest(view: MergeEditorComponent, text: string): void {
290
+ * view.setConflictText(0, text);
291
+ * }
292
+ * ```
293
+ */
294
+ setConflictText(index: number, text: string): void;
295
+ /**
296
+ * Moves the caret to the start of one conflict in the result and names it
297
+ * for screen readers; nothing happens when there is no result.
298
+ *
299
+ * @param index The conflict's index, from 0.
300
+ * @throws {ArgumentOutOfRangeException} When the merge has no conflict at
301
+ * the index.
302
+ * @example
303
+ * ```ts
304
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
305
+ *
306
+ * function showFirst(view: MergeEditorComponent): void {
307
+ * if (view.unresolvedCount() > 0)
308
+ * view.revealConflict(0);
309
+ * }
310
+ * ```
311
+ */
312
+ revealConflict(index: number): void;
313
+ /**
314
+ * Moves the caret to the next conflict, or, from outside every conflict,
315
+ * to the first one after it; past the last one, it says so for screen
316
+ * readers and stays.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
321
+ *
322
+ * function onNext(view: MergeEditorComponent): void {
323
+ * view.nextConflict();
324
+ * }
325
+ * ```
326
+ */
327
+ nextConflict(): void;
328
+ /**
329
+ * Moves the caret to the previous conflict, or, from outside every
330
+ * conflict, to the last one before it; before the first one, it says so
331
+ * for screen readers and stays.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
336
+ *
337
+ * function onPrevious(view: MergeEditorComponent): void {
338
+ * view.previousConflict();
339
+ * }
340
+ * ```
341
+ */
342
+ previousConflict(): void;
343
+ /**
344
+ * Undoes the result's last step, choices included; nothing happens when
345
+ * there is no result.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
350
+ *
351
+ * function onUndo(view: MergeEditorComponent): void {
352
+ * view.undo();
353
+ * }
354
+ * ```
355
+ */
356
+ undo(): void;
357
+ /**
358
+ * Redoes the result's last undone step; nothing happens when there is no
359
+ * result.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
364
+ *
365
+ * function onRedo(view: MergeEditorComponent): void {
366
+ * view.redo();
367
+ * }
368
+ * ```
369
+ */
370
+ redo(): void;
371
+ /**
372
+ * Moves the focus into the result; nothing happens when there is no
373
+ * result.
374
+ *
375
+ * @example
376
+ * ```ts
377
+ * import type { MergeEditorComponent } from "@noldova/code.editor.merge.angular";
378
+ *
379
+ * function startResolving(view: MergeEditorComponent): void {
380
+ * view.focus();
381
+ * }
382
+ * ```
383
+ */
384
+ focus(): void;
385
+ protected choose(choice: ConflictChoice): void;
386
+ protected resetActive(): void;
387
+ protected onSideAction(event: CodeBarActionEvent, choice: ConflictChoice): void;
388
+ protected onResultAction(merge: MergeDocument, event: CodeBarActionEvent): void;
389
+ protected onSelections(merge: MergeDocument, selections: IReadOnlyList<TextSelection>): void;
390
+ private conflicts;
391
+ private anchors;
392
+ private sideDecorations;
393
+ private chunkDecorations;
394
+ private view;
395
+ private restore;
396
+ private onOpen;
397
+ private onResultChange;
398
+ private setActive;
399
+ private step;
400
+ private choosableMerge;
401
+ private announce;
402
+ private onKeyDown;
403
+ private static open;
404
+ private static activeOf;
405
+ static ɵfac: i0.ɵɵFactoryDeclaration<MergeEditorComponent, never>;
406
+ static ɵcmp: i0.ɵɵComponentDeclaration<MergeEditorComponent, "noldova-merge-editor", never, { "base": { "alias": "base"; "required": true; "isSignal": true; }; "ours": { "alias": "ours"; "required": true; "isSignal": true; }; "theirs": { "alias": "theirs"; "required": true; "isSignal": true; }; "merged": { "alias": "merged"; "required": false; "isSignal": true; }; "language": { "alias": "language"; "required": false; "isSignal": true; }; "oursLabel": { "alias": "oursLabel"; "required": true; "isSignal": true; }; "theirsLabel": { "alias": "theirsLabel"; "required": true; "isSignal": true; }; "readOnly": { "alias": "readOnly"; "required": false; "isSignal": true; }; "toolbar": { "alias": "toolbar"; "required": false; "isSignal": true; }; "panels": { "alias": "panels"; "required": false; "isSignal": true; }; "showBase": { "alias": "showBase"; "required": false; "isSignal": true; }; }, { "resultChange": "resultChange"; "conflictsChange": "conflictsChange"; "activeConflictChange": "activeConflictChange"; "markersFailed": "markersFailed"; "keySequencePending": "keySequencePending"; }, never, ["[nolMergeOursHead]", "[nolMergeBaseHead]", "[nolMergeTheirsHead]", "[nolMergeResultHead]"], true, never>;
407
+ }