@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 +21 -0
- package/README.md +6 -2
- package/api/index.d.ts +10 -0
- package/api/index.js +10 -0
- package/app/components/merge-editor/merge-editor.component.d.ts +407 -0
- package/app/components/merge-editor/merge-editor.component.js +331 -0
- package/app/models/active-conflict.d.ts +58 -0
- package/app/models/active-conflict.js +23 -0
- package/app/models/conflict-chunk.d.ts +17 -0
- package/app/models/conflict-chunk.js +21 -0
- package/app/models/conflict-lines.d.ts +13 -0
- package/app/models/conflict-lines.js +27 -0
- package/app/models/merge-marks.d.ts +19 -0
- package/app/models/merge-marks.js +83 -0
- package/app/models/merge-opening.d.ts +13 -0
- package/app/models/merge-opening.js +15 -0
- package/package.json +39 -4
- package/resources.d.ts +69 -0
- package/resources.js +89 -0
|
@@ -0,0 +1,331 @@
|
|
|
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 { Component, computed, DestroyRef, effect, ElementRef, inject, input, output, signal, untracked, viewChild } from "@angular/core";
|
|
10
|
+
import { Required, TextDocument, TextSelection, UndoHistory } from "@noldova/code.editor";
|
|
11
|
+
import { CodeBarAction, CodeEditorComponent, KeyScope } from "@noldova/code.editor.angular";
|
|
12
|
+
import { ConflictChoice, ConflictMarkersException, ConflictState, MergeDocument } from "@noldova/code.editor.merge";
|
|
13
|
+
import { List } from "@noldova/context.collections";
|
|
14
|
+
import { ButtonComponent, ButtonSize, ButtonVariant, IconButtonComponent } from "@noldova/ui.components.angular";
|
|
15
|
+
import { Resources } from "../../../resources.js";
|
|
16
|
+
import { ActiveConflict } from "../../models/active-conflict.js";
|
|
17
|
+
import { ConflictChunk } from "../../models/conflict-chunk.js";
|
|
18
|
+
import { ConflictLines } from "../../models/conflict-lines.js";
|
|
19
|
+
import { MergeMarks } from "../../models/merge-marks.js";
|
|
20
|
+
import { MergeOpening } from "../../models/merge-opening.js";
|
|
21
|
+
import * as i0 from "@angular/core";
|
|
22
|
+
export class MergeEditorComponent {
|
|
23
|
+
static BAR_CHOICES = new Map([
|
|
24
|
+
[Resources.oursAction, ConflictChoice.Ours],
|
|
25
|
+
[Resources.theirsAction, ConflictChoice.Theirs],
|
|
26
|
+
[Resources.bothAction, ConflictChoice.BothOursFirst]
|
|
27
|
+
]);
|
|
28
|
+
resultView = viewChild("result", /* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [{ debugName: "resultView" }] : /* istanbul ignore next */ []));
|
|
30
|
+
version = signal(0, /* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
32
|
+
cleanText = null;
|
|
33
|
+
reportedStates = null;
|
|
34
|
+
base = input.required(/* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "base" }] : /* istanbul ignore next */ []));
|
|
36
|
+
ours = input.required(/* @ts-ignore */
|
|
37
|
+
...(ngDevMode ? [{ debugName: "ours" }] : /* istanbul ignore next */ []));
|
|
38
|
+
theirs = input.required(/* @ts-ignore */
|
|
39
|
+
...(ngDevMode ? [{ debugName: "theirs" }] : /* istanbul ignore next */ []));
|
|
40
|
+
merged = input(null, /* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [{ debugName: "merged" }] : /* istanbul ignore next */ []));
|
|
42
|
+
language = input(null, /* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "language" }] : /* istanbul ignore next */ []));
|
|
44
|
+
oursLabel = input.required(/* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [{ debugName: "oursLabel" }] : /* istanbul ignore next */ []));
|
|
46
|
+
theirsLabel = input.required(/* @ts-ignore */
|
|
47
|
+
...(ngDevMode ? [{ debugName: "theirsLabel" }] : /* istanbul ignore next */ []));
|
|
48
|
+
readOnly = input(false, /* @ts-ignore */
|
|
49
|
+
...(ngDevMode ? [{ debugName: "readOnly" }] : /* istanbul ignore next */ []));
|
|
50
|
+
toolbar = input(true, /* @ts-ignore */
|
|
51
|
+
...(ngDevMode ? [{ debugName: "toolbar" }] : /* istanbul ignore next */ []));
|
|
52
|
+
panels = input(false, /* @ts-ignore */
|
|
53
|
+
...(ngDevMode ? [{ debugName: "panels" }] : /* istanbul ignore next */ []));
|
|
54
|
+
showBase = input(false, /* @ts-ignore */
|
|
55
|
+
...(ngDevMode ? [{ debugName: "showBase" }] : /* istanbul ignore next */ []));
|
|
56
|
+
resultChange = output();
|
|
57
|
+
conflictsChange = output();
|
|
58
|
+
activeConflictChange = output();
|
|
59
|
+
markersFailed = output();
|
|
60
|
+
keySequencePending = output();
|
|
61
|
+
activeConflict = computed(() => {
|
|
62
|
+
this.version();
|
|
63
|
+
const index = this.active();
|
|
64
|
+
const merge = this.opening().merge;
|
|
65
|
+
return Object.isNull(index) || Object.isNull(merge) ? null : MergeEditorComponent.activeOf(merge, index, this.base());
|
|
66
|
+
}, /* @ts-ignore */
|
|
67
|
+
...(ngDevMode ? [{ debugName: "activeConflict" }] : /* istanbul ignore next */ []));
|
|
68
|
+
resources = Resources;
|
|
69
|
+
choices = ConflictChoice;
|
|
70
|
+
compact = ButtonSize.Compact;
|
|
71
|
+
secondary = ButtonVariant.Secondary;
|
|
72
|
+
opening = computed(() => MergeEditorComponent.open(this.base(), this.ours(), this.theirs(), this.merged()), /* @ts-ignore */
|
|
73
|
+
...(ngDevMode ? [{ debugName: "opening" }] : /* istanbul ignore next */ []));
|
|
74
|
+
active = signal(null, /* @ts-ignore */
|
|
75
|
+
...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
76
|
+
announcement = signal(Resources.empty, /* @ts-ignore */
|
|
77
|
+
...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
|
|
78
|
+
oursDocument = computed(() => TextDocument.fromText(Required.value(this.ours())), /* @ts-ignore */
|
|
79
|
+
...(ngDevMode ? [{ debugName: "oursDocument" }] : /* istanbul ignore next */ []));
|
|
80
|
+
theirsDocument = computed(() => TextDocument.fromText(Required.value(this.theirs())), /* @ts-ignore */
|
|
81
|
+
...(ngDevMode ? [{ debugName: "theirsDocument" }] : /* istanbul ignore next */ []));
|
|
82
|
+
oursHistory = computed(() => new UndoHistory(this.oursDocument()), /* @ts-ignore */
|
|
83
|
+
...(ngDevMode ? [{ debugName: "oursHistory" }] : /* istanbul ignore next */ []));
|
|
84
|
+
theirsHistory = computed(() => new UndoHistory(this.theirsDocument()), /* @ts-ignore */
|
|
85
|
+
...(ngDevMode ? [{ debugName: "theirsHistory" }] : /* istanbul ignore next */ []));
|
|
86
|
+
oursLines = computed(() => ConflictLines.of(this.oursDocument(), this.conflicts().select(t => t.ours).toList(), this.anchors()), /* @ts-ignore */
|
|
87
|
+
...(ngDevMode ? [{ debugName: "oursLines" }] : /* istanbul ignore next */ []));
|
|
88
|
+
theirsLines = computed(() => ConflictLines.of(this.theirsDocument(), this.conflicts().select(t => t.theirs).toList(), this.anchors()), /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "theirsLines" }] : /* istanbul ignore next */ []));
|
|
90
|
+
oursDecorations = computed(() => new List([
|
|
91
|
+
this.sideDecorations(Resources.oursBackground, ConflictChoice.Ours, this.oursLines())
|
|
92
|
+
]), /* @ts-ignore */
|
|
93
|
+
...(ngDevMode ? [{ debugName: "oursDecorations" }] : /* istanbul ignore next */ []));
|
|
94
|
+
theirsDecorations = computed(() => new List([
|
|
95
|
+
this.sideDecorations(Resources.theirsBackground, ConflictChoice.Theirs, this.theirsLines())
|
|
96
|
+
]), /* @ts-ignore */
|
|
97
|
+
...(ngDevMode ? [{ debugName: "theirsDecorations" }] : /* istanbul ignore next */ []));
|
|
98
|
+
baseDocument = computed(() => TextDocument.fromText(this.base() ?? Resources.empty), /* @ts-ignore */
|
|
99
|
+
...(ngDevMode ? [{ debugName: "baseDocument" }] : /* istanbul ignore next */ []));
|
|
100
|
+
baseHistory = computed(() => new UndoHistory(this.baseDocument()), /* @ts-ignore */
|
|
101
|
+
...(ngDevMode ? [{ debugName: "baseHistory" }] : /* istanbul ignore next */ []));
|
|
102
|
+
baseDecorations = computed(() => new List([this.chunkDecorations(null, ConflictLines.of(this.baseDocument(), this.conflicts().select(t => t.base).toList(), this.anchors()), t => t.base, new List())]), /* @ts-ignore */
|
|
103
|
+
...(ngDevMode ? [{ debugName: "baseDecorations" }] : /* istanbul ignore next */ []));
|
|
104
|
+
survivorIsOurs = computed(() => !Object.isNull(this.ours()), /* @ts-ignore */
|
|
105
|
+
...(ngDevMode ? [{ debugName: "survivorIsOurs" }] : /* istanbul ignore next */ []));
|
|
106
|
+
deletedNote = computed(() => Resources.formatDeleted(this.survivorIsOurs() ? this.theirsLabel() : this.oursLabel()), /* @ts-ignore */
|
|
107
|
+
...(ngDevMode ? [{ debugName: "deletedNote" }] : /* istanbul ignore next */ []));
|
|
108
|
+
states = computed(() => {
|
|
109
|
+
this.version();
|
|
110
|
+
const merge = this.opening().merge;
|
|
111
|
+
return Object.isNull(merge) ? new List() : merge.conflicts.select(t => merge.stateOf(t.index)).toList();
|
|
112
|
+
}, /* @ts-ignore */
|
|
113
|
+
...(ngDevMode ? [{ debugName: "states" }] : /* istanbul ignore next */ []));
|
|
114
|
+
summary = computed(() => {
|
|
115
|
+
const states = this.states();
|
|
116
|
+
return states.count() === 0 ? Resources.noConflicts : Resources.formatUnresolved(states.count(t => t === ConflictState.Unresolved), states.count());
|
|
117
|
+
}, /* @ts-ignore */
|
|
118
|
+
...(ngDevMode ? [{ debugName: "summary" }] : /* istanbul ignore next */ []));
|
|
119
|
+
resultDecorations = computed(() => {
|
|
120
|
+
this.version();
|
|
121
|
+
return new List([MergeMarks.resultOf(Required.value(this.opening().merge), !this.readOnly())]);
|
|
122
|
+
}, /* @ts-ignore */
|
|
123
|
+
...(ngDevMode ? [{ debugName: "resultDecorations" }] : /* istanbul ignore next */ []));
|
|
124
|
+
canChoose = computed(() => !this.readOnly() && !Object.isNull(this.active()), /* @ts-ignore */
|
|
125
|
+
...(ngDevMode ? [{ debugName: "canChoose" }] : /* istanbul ignore next */ []));
|
|
126
|
+
constructor() {
|
|
127
|
+
inject(KeyScope).listen(t => this.keySequencePending.emit(t));
|
|
128
|
+
effect(onCleanup => {
|
|
129
|
+
const opening = this.opening();
|
|
130
|
+
untracked(() => this.onOpen(opening));
|
|
131
|
+
const merge = opening.merge;
|
|
132
|
+
if (!Object.isNull(merge))
|
|
133
|
+
onCleanup(merge.document.onChange(() => this.onResultChange(merge)));
|
|
134
|
+
});
|
|
135
|
+
effect(() => {
|
|
136
|
+
const states = this.states();
|
|
137
|
+
const key = states.toArray().join();
|
|
138
|
+
if (key !== this.reportedStates) {
|
|
139
|
+
this.reportedStates = key;
|
|
140
|
+
untracked(() => this.conflictsChange.emit(states));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const host = inject(ElementRef).nativeElement;
|
|
144
|
+
const listener = event => this.onKeyDown(event);
|
|
145
|
+
host.addEventListener(Resources.keyDown, listener, true);
|
|
146
|
+
inject(DestroyRef).onDestroy(() => host.removeEventListener(Resources.keyDown, listener, true));
|
|
147
|
+
}
|
|
148
|
+
result() {
|
|
149
|
+
return this.opening().merge?.document.text() ?? null;
|
|
150
|
+
}
|
|
151
|
+
unresolvedCount() {
|
|
152
|
+
return this.opening().merge?.unresolvedCount() ?? 0;
|
|
153
|
+
}
|
|
154
|
+
dirty() {
|
|
155
|
+
return this.result() !== this.cleanText;
|
|
156
|
+
}
|
|
157
|
+
markClean() {
|
|
158
|
+
this.cleanText = this.result();
|
|
159
|
+
}
|
|
160
|
+
accept(index, choice) {
|
|
161
|
+
const merge = this.choosableMerge();
|
|
162
|
+
if (Object.isNull(merge))
|
|
163
|
+
return;
|
|
164
|
+
merge.accept(index, choice, performance.now());
|
|
165
|
+
this.announce(merge, index);
|
|
166
|
+
}
|
|
167
|
+
acceptAll(choice) {
|
|
168
|
+
this.choosableMerge()?.acceptAll(choice, performance.now());
|
|
169
|
+
}
|
|
170
|
+
reset(index) {
|
|
171
|
+
const merge = this.choosableMerge();
|
|
172
|
+
if (Object.isNull(merge))
|
|
173
|
+
return;
|
|
174
|
+
merge.reset(index, performance.now());
|
|
175
|
+
this.announce(merge, index);
|
|
176
|
+
}
|
|
177
|
+
setConflictText(index, text) {
|
|
178
|
+
const merge = this.choosableMerge();
|
|
179
|
+
if (Object.isNull(merge))
|
|
180
|
+
return;
|
|
181
|
+
merge.setConflictText(index, text, performance.now());
|
|
182
|
+
this.announce(merge, index);
|
|
183
|
+
}
|
|
184
|
+
revealConflict(index) {
|
|
185
|
+
const merge = this.opening().merge;
|
|
186
|
+
if (Object.isNull(merge))
|
|
187
|
+
return;
|
|
188
|
+
const conflict = merge.conflicts.get(index);
|
|
189
|
+
this.view().select(new List([new TextSelection(merge.document.positionAt(conflict.start))]));
|
|
190
|
+
this.setActive(index);
|
|
191
|
+
this.announce(merge, index);
|
|
192
|
+
}
|
|
193
|
+
nextConflict() {
|
|
194
|
+
this.step(1);
|
|
195
|
+
}
|
|
196
|
+
previousConflict() {
|
|
197
|
+
this.step(-1);
|
|
198
|
+
}
|
|
199
|
+
undo() {
|
|
200
|
+
this.restore(t => t.history.undo());
|
|
201
|
+
}
|
|
202
|
+
redo() {
|
|
203
|
+
this.restore(t => t.history.redo());
|
|
204
|
+
}
|
|
205
|
+
focus() {
|
|
206
|
+
if (!Object.isNull(this.opening().merge))
|
|
207
|
+
this.view().focus();
|
|
208
|
+
}
|
|
209
|
+
choose(choice) {
|
|
210
|
+
this.accept(Required.value(this.active()), choice);
|
|
211
|
+
}
|
|
212
|
+
resetActive() {
|
|
213
|
+
this.reset(Required.value(this.active()));
|
|
214
|
+
}
|
|
215
|
+
onSideAction(event, choice) {
|
|
216
|
+
this.accept(Number(event.bar.id), choice);
|
|
217
|
+
}
|
|
218
|
+
onResultAction(merge, event) {
|
|
219
|
+
const index = Number(event.bar.id);
|
|
220
|
+
if (event.action.id === Resources.suggestedAction)
|
|
221
|
+
this.setConflictText(index, Required.value(merge.conflicts.get(index).suggestion));
|
|
222
|
+
else
|
|
223
|
+
this.accept(index, Required.value(MergeEditorComponent.BAR_CHOICES.get(event.action.id)));
|
|
224
|
+
}
|
|
225
|
+
onSelections(merge, selections) {
|
|
226
|
+
this.setActive(merge.conflictAt(merge.document.offsetAt(selections.get(0).head)));
|
|
227
|
+
}
|
|
228
|
+
conflicts() {
|
|
229
|
+
return Required.value(this.opening().merge).conflicts;
|
|
230
|
+
}
|
|
231
|
+
anchors() {
|
|
232
|
+
const merge = Required.value(this.opening().merge);
|
|
233
|
+
return merge.conflicts.select(t => {
|
|
234
|
+
const end = merge.document.positionAt(t.end);
|
|
235
|
+
return merge.document.lineText(end.line).slice(end.column);
|
|
236
|
+
}).toList();
|
|
237
|
+
}
|
|
238
|
+
sideDecorations(background, side, lines) {
|
|
239
|
+
const actions = this.readOnly() ? new List()
|
|
240
|
+
: new List([new CodeBarAction(Resources.takeAction, Resources.takeLabel, Resources.takeIcon)]);
|
|
241
|
+
return this.chunkDecorations(background, lines, t => t.choiceText(side), actions);
|
|
242
|
+
}
|
|
243
|
+
chunkDecorations(background, lines, textOf, actions) {
|
|
244
|
+
const states = this.states();
|
|
245
|
+
const chunks = this.conflicts().selectMany((t) => {
|
|
246
|
+
const line = lines.get(t.index);
|
|
247
|
+
return Object.isNull(line) ? [] : [new ConflictChunk(line, t.index, ConflictLines.countOf(textOf(t)), Resources.formatChunk(t.index + 1, states.get(t.index)), actions)];
|
|
248
|
+
}).toList();
|
|
249
|
+
return MergeMarks.sideOf(chunks, background);
|
|
250
|
+
}
|
|
251
|
+
view() {
|
|
252
|
+
return Required.value(this.resultView());
|
|
253
|
+
}
|
|
254
|
+
restore(step) {
|
|
255
|
+
const merge = this.opening().merge;
|
|
256
|
+
if (Object.isNull(merge))
|
|
257
|
+
return;
|
|
258
|
+
const selections = step(merge);
|
|
259
|
+
if (!Object.isNull(selections))
|
|
260
|
+
this.view().select(selections);
|
|
261
|
+
}
|
|
262
|
+
onOpen(opening) {
|
|
263
|
+
this.cleanText = opening.merge?.document.text() ?? null;
|
|
264
|
+
this.setActive(null);
|
|
265
|
+
this.version.update(t => t + 1);
|
|
266
|
+
if (!Object.isNull(opening.failure))
|
|
267
|
+
this.markersFailed.emit(opening.failure);
|
|
268
|
+
}
|
|
269
|
+
onResultChange(merge) {
|
|
270
|
+
this.version.update(t => t + 1);
|
|
271
|
+
this.resultChange.emit(merge.document.text());
|
|
272
|
+
}
|
|
273
|
+
setActive(index) {
|
|
274
|
+
if (index === this.active())
|
|
275
|
+
return;
|
|
276
|
+
this.active.set(index);
|
|
277
|
+
this.activeConflictChange.emit(index);
|
|
278
|
+
}
|
|
279
|
+
step(direction) {
|
|
280
|
+
const merge = this.opening().merge;
|
|
281
|
+
if (Object.isNull(merge))
|
|
282
|
+
return;
|
|
283
|
+
const current = this.active();
|
|
284
|
+
const offset = merge.document.offsetAt(this.view().caret());
|
|
285
|
+
const index = !Object.isNull(current)
|
|
286
|
+
? current + direction
|
|
287
|
+
: direction > 0 ? merge.conflicts.firstOrDefault(t => t.start >= offset)?.index ?? -1 : merge.conflicts.lastOrDefault(t => t.end <= offset)?.index ?? -1;
|
|
288
|
+
if (index < 0 || index >= merge.conflicts.count()) {
|
|
289
|
+
this.announcement.set(merge.conflicts.count() === 0 ? Resources.noConflicts : Resources.noMoreConflicts);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
this.revealConflict(index);
|
|
293
|
+
}
|
|
294
|
+
choosableMerge() {
|
|
295
|
+
return this.readOnly() ? null : this.opening().merge;
|
|
296
|
+
}
|
|
297
|
+
announce(merge, index) {
|
|
298
|
+
this.announcement.set(Resources.formatConflict(index + 1, merge.conflicts.count(), merge.stateOf(index), merge.unresolvedCount()));
|
|
299
|
+
}
|
|
300
|
+
onKeyDown(event) {
|
|
301
|
+
if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.key !== Resources.keyArrowDown && event.key !== Resources.keyArrowUp)
|
|
302
|
+
return;
|
|
303
|
+
event.preventDefault();
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
this.step(event.key === Resources.keyArrowDown ? 1 : -1);
|
|
306
|
+
this.focus();
|
|
307
|
+
}
|
|
308
|
+
static open(base, ours, theirs, merged) {
|
|
309
|
+
if (Object.isNull(ours) || Object.isNull(theirs))
|
|
310
|
+
return new MergeOpening(null, null);
|
|
311
|
+
if (Object.isNull(merged))
|
|
312
|
+
return new MergeOpening(MergeDocument.fromSides(base ?? Resources.empty, ours, theirs), null);
|
|
313
|
+
const read = MergeDocument.readMarkers(merged);
|
|
314
|
+
return read instanceof ConflictMarkersException ? new MergeOpening(null, read) : new MergeOpening(read, null);
|
|
315
|
+
}
|
|
316
|
+
static activeOf(merge, index, base) {
|
|
317
|
+
const conflict = merge.conflicts.get(index);
|
|
318
|
+
const first = merge.document.positionAt(conflict.start);
|
|
319
|
+
const last = merge.document.positionAt(conflict.end);
|
|
320
|
+
return new ActiveConflict(index, merge.conflicts.count(), Object.isNull(base) ? null : conflict.base, merge.stateOf(index), first.line, conflict.end > conflict.start && last.column === 0 ? last.line - 1 : last.line);
|
|
321
|
+
}
|
|
322
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MergeEditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
323
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: MergeEditorComponent, isStandalone: true, selector: "noldova-merge-editor", inputs: { base: { classPropertyName: "base", publicName: "base", isSignal: true, isRequired: true, transformFunction: null }, ours: { classPropertyName: "ours", publicName: "ours", isSignal: true, isRequired: true, transformFunction: null }, theirs: { classPropertyName: "theirs", publicName: "theirs", isSignal: true, isRequired: true, transformFunction: null }, merged: { classPropertyName: "merged", publicName: "merged", isSignal: true, isRequired: false, transformFunction: null }, language: { classPropertyName: "language", publicName: "language", isSignal: true, isRequired: false, transformFunction: null }, oursLabel: { classPropertyName: "oursLabel", publicName: "oursLabel", isSignal: true, isRequired: true, transformFunction: null }, theirsLabel: { classPropertyName: "theirsLabel", publicName: "theirsLabel", isSignal: true, isRequired: true, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, toolbar: { classPropertyName: "toolbar", publicName: "toolbar", isSignal: true, isRequired: false, transformFunction: null }, panels: { classPropertyName: "panels", publicName: "panels", isSignal: true, isRequired: false, transformFunction: null }, showBase: { classPropertyName: "showBase", publicName: "showBase", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { resultChange: "resultChange", conflictsChange: "conflictsChange", activeConflictChange: "activeConflictChange", markersFailed: "markersFailed", keySequencePending: "keySequencePending" }, host: { properties: { "class.nol-merge-editor-panels": "panels()" }, classAttribute: "nol-merge-editor" }, providers: [KeyScope], viewQueries: [{ propertyName: "resultView", first: true, predicate: ["result"], 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 (opening().failure; as failure) {\n <p class=\"nol-merge-editor-note nol-merge-editor-failure\" role=\"alert\">{{ failure.message }}</p>\n} @else if (opening().merge; as merge) {\n <div class=\"nol-merge-editor-sides\">\n <div class=\"nol-merge-editor-side\">\n <ng-content select=\"[nolMergeOursHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"oursDocument()\" [history]=\"oursHistory()\" [language]=\"language()\" [label]=\"oursLabel()\"\n [readOnly]=\"true\" [decorations]=\"oursDecorations()\" (barAction)=\"onSideAction($event, choices.Ours)\" />\n </div>\n @if (showBase()) {\n <div class=\"nol-merge-editor-side nol-merge-editor-base\">\n <ng-content select=\"[nolMergeBaseHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"baseDocument()\" [history]=\"baseHistory()\" [language]=\"language()\" [label]=\"resources.baseLabel\"\n [readOnly]=\"true\" [decorations]=\"baseDecorations()\" />\n </div>\n }\n <div class=\"nol-merge-editor-side\">\n <ng-content select=\"[nolMergeTheirsHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"theirsDocument()\" [history]=\"theirsHistory()\" [language]=\"language()\" [label]=\"theirsLabel()\"\n [readOnly]=\"true\" [decorations]=\"theirsDecorations()\" (barAction)=\"onSideAction($event, choices.Theirs)\" />\n </div>\n </div>\n @if (toolbar()) {\n <div class=\"nol-merge-editor-bar\">\n <span class=\"nol-merge-editor-summary\">{{ summary() }}</span>\n <button nol-icon-button type=\"button\" icon=\"arrow_upward\" [label]=\"resources.previousConflictLabel\" (click)=\"previousConflict()\"></button>\n <button nol-icon-button type=\"button\" icon=\"arrow_downward\" [label]=\"resources.nextConflictLabel\" (click)=\"nextConflict()\"></button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.Ours)\">{{ resources.acceptOursLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.Theirs)\">{{ resources.acceptTheirsLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.BothOursFirst)\">{{ resources.acceptBothOursFirstLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.BothTheirsFirst)\">{{ resources.acceptBothTheirsFirstLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"resetActive()\">{{ resources.resetLabel }}</button>\n </div>\n }\n <div class=\"nol-merge-editor-output\">\n <ng-content select=\"[nolMergeResultHead]\" />\n <noldova-code-editor #result class=\"nol-merge-editor-result\" [document]=\"merge.document\" [history]=\"merge.history\" [language]=\"language()\"\n [label]=\"resources.resultLabel\" [readOnly]=\"readOnly()\" [decorations]=\"resultDecorations()\" (selectionsChange)=\"onSelections(merge, $event)\"\n (barAction)=\"onResultAction(merge, $event)\" />\n </div>\n} @else {\n <p class=\"nol-merge-editor-note\" role=\"note\">{{ deletedNote() }}</p>\n @if (survivorIsOurs()) {\n <noldova-code-editor class=\"nol-merge-editor-result\" [document]=\"oursDocument()\" [history]=\"oursHistory()\" [language]=\"language()\" [label]=\"oursLabel()\"\n [readOnly]=\"true\" />\n } @else {\n <noldova-code-editor class=\"nol-merge-editor-result\" [document]=\"theirsDocument()\" [history]=\"theirsHistory()\" [language]=\"language()\"\n [label]=\"theirsLabel()\" [readOnly]=\"true\" />\n }\n}\n<div class=\"nol-merge-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 flex-direction: column;\n gap: var(--nol-merge-editor-gap, 0);\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-merge-editor-sides {\n display: flex;\n flex: 1 1 0;\n gap: var(--nol-merge-editor-gap, 0);\n min-height: 0;\n}\n\n.nol-merge-editor-side,\n.nol-merge-editor-output {\n display: flex;\n flex-direction: column;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n}\n\n.nol-merge-editor-side {\n flex: 1 1 0;\n}\n\n.nol-merge-editor-output {\n flex: 1.1 1 0;\n}\n\n.nol-merge-editor-side + .nol-merge-editor-side {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n:host(.nol-merge-editor-panels) {\n background-color: transparent;\n}\n\n:host(.nol-merge-editor-panels) .nol-merge-editor-side,\n:host(.nol-merge-editor-panels) .nol-merge-editor-output {\n border: var(--nol-border-width) solid var(--nol-card-border);\n border-radius: var(--nol-radius-large);\n background-color: var(--nol-panel);\n}\n\n.nol-merge-editor-pane,\n.nol-merge-editor-result {\n --nol-code-editor-font-size: 0.8125rem;\n --nol-code-editor-line-height: 1.25rem;\n --nol-code-editor-gutter-width: 2.75rem;\n --nol-code-editor-gutter-end: 0.75rem;\n --nol-code-editor-signs: none;\n --nol-code-editor-inset: 0;\n}\n\n.nol-merge-editor-pane,\n.nol-merge-editor-result {\n flex: 1 1 0;\n min-height: 0;\n}\n\n.nol-merge-editor-bar {\n display: flex;\n align-items: center;\n gap: var(--nol-space-1);\n padding: var(--nol-space-1) var(--nol-space-2);\n border-block: var(--nol-border-width) solid var(--nol-card-border);\n background-color: var(--nol-panel);\n}\n\n.nol-merge-editor-summary {\n flex: 1 1 auto;\n min-width: 0;\n overflow: hidden;\n color: var(--nol-text-muted);\n font-family: var(--nol-font-sans);\n font-size: var(--nol-text-label);\n line-height: var(--nol-line-label);\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.nol-merge-editor-note {\n margin: 0;\n padding: var(--nol-space-2);\n border-block-end: var(--nol-border-width) solid var(--nol-card-border);\n background-color: var(--nol-warning-background);\n color: var(--nol-text);\n font-family: var(--nol-font-sans);\n font-size: var(--nol-text-label);\n line-height: var(--nol-line-label);\n}\n\n.nol-merge-editor-failure {\n border-block-end: none;\n background-color: var(--nol-error-background);\n}\n\n.nol-merge-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: ButtonComponent, selector: "button[nol-button], a[nol-button]", inputs: ["variant", "overlay", "backdrop", "danger", "size", "busy"] }, { kind: "component", type: CodeEditorComponent, selector: "noldova-code-editor", inputs: ["document", "history", "language", "label", "readOnly", "tabIndents", "decorations", "folds"], outputs: ["selectionsChange", "scrollChange", "foldToggle", "barAction", "keySequencePending"] }, { kind: "component", type: IconButtonComponent, selector: "button[nol-icon-button]", inputs: ["icon", "label", "pressed", "filled", "overlay", "backdrop", "buttonHeight", "danger", "tabAction", "busy", "busyPressable"] }] });
|
|
324
|
+
}
|
|
325
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MergeEditorComponent, decorators: [{
|
|
326
|
+
type: Component,
|
|
327
|
+
args: [{ selector: "noldova-merge-editor", imports: [ButtonComponent, CodeEditorComponent, IconButtonComponent], providers: [KeyScope], host: {
|
|
328
|
+
"class": Resources.mergeEditorClass,
|
|
329
|
+
[Resources.panelsClassBinding]: "panels()"
|
|
330
|
+
}, 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 (opening().failure; as failure) {\n <p class=\"nol-merge-editor-note nol-merge-editor-failure\" role=\"alert\">{{ failure.message }}</p>\n} @else if (opening().merge; as merge) {\n <div class=\"nol-merge-editor-sides\">\n <div class=\"nol-merge-editor-side\">\n <ng-content select=\"[nolMergeOursHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"oursDocument()\" [history]=\"oursHistory()\" [language]=\"language()\" [label]=\"oursLabel()\"\n [readOnly]=\"true\" [decorations]=\"oursDecorations()\" (barAction)=\"onSideAction($event, choices.Ours)\" />\n </div>\n @if (showBase()) {\n <div class=\"nol-merge-editor-side nol-merge-editor-base\">\n <ng-content select=\"[nolMergeBaseHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"baseDocument()\" [history]=\"baseHistory()\" [language]=\"language()\" [label]=\"resources.baseLabel\"\n [readOnly]=\"true\" [decorations]=\"baseDecorations()\" />\n </div>\n }\n <div class=\"nol-merge-editor-side\">\n <ng-content select=\"[nolMergeTheirsHead]\" />\n <noldova-code-editor class=\"nol-merge-editor-pane\" [document]=\"theirsDocument()\" [history]=\"theirsHistory()\" [language]=\"language()\" [label]=\"theirsLabel()\"\n [readOnly]=\"true\" [decorations]=\"theirsDecorations()\" (barAction)=\"onSideAction($event, choices.Theirs)\" />\n </div>\n </div>\n @if (toolbar()) {\n <div class=\"nol-merge-editor-bar\">\n <span class=\"nol-merge-editor-summary\">{{ summary() }}</span>\n <button nol-icon-button type=\"button\" icon=\"arrow_upward\" [label]=\"resources.previousConflictLabel\" (click)=\"previousConflict()\"></button>\n <button nol-icon-button type=\"button\" icon=\"arrow_downward\" [label]=\"resources.nextConflictLabel\" (click)=\"nextConflict()\"></button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.Ours)\">{{ resources.acceptOursLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.Theirs)\">{{ resources.acceptTheirsLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.BothOursFirst)\">{{ resources.acceptBothOursFirstLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"choose(choices.BothTheirsFirst)\">{{ resources.acceptBothTheirsFirstLabel }}</button>\n <button nol-button type=\"button\" [variant]=\"secondary\" [size]=\"compact\" [disabled]=\"!canChoose()\" (click)=\"resetActive()\">{{ resources.resetLabel }}</button>\n </div>\n }\n <div class=\"nol-merge-editor-output\">\n <ng-content select=\"[nolMergeResultHead]\" />\n <noldova-code-editor #result class=\"nol-merge-editor-result\" [document]=\"merge.document\" [history]=\"merge.history\" [language]=\"language()\"\n [label]=\"resources.resultLabel\" [readOnly]=\"readOnly()\" [decorations]=\"resultDecorations()\" (selectionsChange)=\"onSelections(merge, $event)\"\n (barAction)=\"onResultAction(merge, $event)\" />\n </div>\n} @else {\n <p class=\"nol-merge-editor-note\" role=\"note\">{{ deletedNote() }}</p>\n @if (survivorIsOurs()) {\n <noldova-code-editor class=\"nol-merge-editor-result\" [document]=\"oursDocument()\" [history]=\"oursHistory()\" [language]=\"language()\" [label]=\"oursLabel()\"\n [readOnly]=\"true\" />\n } @else {\n <noldova-code-editor class=\"nol-merge-editor-result\" [document]=\"theirsDocument()\" [history]=\"theirsHistory()\" [language]=\"language()\"\n [label]=\"theirsLabel()\" [readOnly]=\"true\" />\n }\n}\n<div class=\"nol-merge-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 flex-direction: column;\n gap: var(--nol-merge-editor-gap, 0);\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-merge-editor-sides {\n display: flex;\n flex: 1 1 0;\n gap: var(--nol-merge-editor-gap, 0);\n min-height: 0;\n}\n\n.nol-merge-editor-side,\n.nol-merge-editor-output {\n display: flex;\n flex-direction: column;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n}\n\n.nol-merge-editor-side {\n flex: 1 1 0;\n}\n\n.nol-merge-editor-output {\n flex: 1.1 1 0;\n}\n\n.nol-merge-editor-side + .nol-merge-editor-side {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n:host(.nol-merge-editor-panels) {\n background-color: transparent;\n}\n\n:host(.nol-merge-editor-panels) .nol-merge-editor-side,\n:host(.nol-merge-editor-panels) .nol-merge-editor-output {\n border: var(--nol-border-width) solid var(--nol-card-border);\n border-radius: var(--nol-radius-large);\n background-color: var(--nol-panel);\n}\n\n.nol-merge-editor-pane,\n.nol-merge-editor-result {\n --nol-code-editor-font-size: 0.8125rem;\n --nol-code-editor-line-height: 1.25rem;\n --nol-code-editor-gutter-width: 2.75rem;\n --nol-code-editor-gutter-end: 0.75rem;\n --nol-code-editor-signs: none;\n --nol-code-editor-inset: 0;\n}\n\n.nol-merge-editor-pane,\n.nol-merge-editor-result {\n flex: 1 1 0;\n min-height: 0;\n}\n\n.nol-merge-editor-bar {\n display: flex;\n align-items: center;\n gap: var(--nol-space-1);\n padding: var(--nol-space-1) var(--nol-space-2);\n border-block: var(--nol-border-width) solid var(--nol-card-border);\n background-color: var(--nol-panel);\n}\n\n.nol-merge-editor-summary {\n flex: 1 1 auto;\n min-width: 0;\n overflow: hidden;\n color: var(--nol-text-muted);\n font-family: var(--nol-font-sans);\n font-size: var(--nol-text-label);\n line-height: var(--nol-line-label);\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.nol-merge-editor-note {\n margin: 0;\n padding: var(--nol-space-2);\n border-block-end: var(--nol-border-width) solid var(--nol-card-border);\n background-color: var(--nol-warning-background);\n color: var(--nol-text);\n font-family: var(--nol-font-sans);\n font-size: var(--nol-text-label);\n line-height: var(--nol-line-label);\n}\n\n.nol-merge-editor-failure {\n border-block-end: none;\n background-color: var(--nol-error-background);\n}\n\n.nol-merge-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"] }]
|
|
331
|
+
}], ctorParameters: () => [], propDecorators: { resultView: [{ type: i0.ViewChild, args: ["result", { isSignal: true }] }], base: [{ type: i0.Input, args: [{ isSignal: true, alias: "base", required: true }] }], ours: [{ type: i0.Input, args: [{ isSignal: true, alias: "ours", required: true }] }], theirs: [{ type: i0.Input, args: [{ isSignal: true, alias: "theirs", required: true }] }], merged: [{ type: i0.Input, args: [{ isSignal: true, alias: "merged", required: false }] }], language: [{ type: i0.Input, args: [{ isSignal: true, alias: "language", required: false }] }], oursLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "oursLabel", required: true }] }], theirsLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "theirsLabel", required: true }] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], toolbar: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolbar", required: false }] }], panels: [{ type: i0.Input, args: [{ isSignal: true, alias: "panels", required: false }] }], showBase: [{ type: i0.Input, args: [{ isSignal: true, alias: "showBase", required: false }] }], resultChange: [{ type: i0.Output, args: ["resultChange"] }], conflictsChange: [{ type: i0.Output, args: ["conflictsChange"] }], activeConflictChange: [{ type: i0.Output, args: ["activeConflictChange"] }], markersFailed: [{ type: i0.Output, args: ["markersFailed"] }], keySequencePending: [{ type: i0.Output, args: ["keySequencePending"] }] } });
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { ConflictState } from "@noldova/code.editor.merge";
|
|
9
|
+
/**
|
|
10
|
+
* Describes the merge conflict that holds the caret in a
|
|
11
|
+
* {@link MergeEditorComponent}, as its `activeConflict` signal gives it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ActiveConflict {
|
|
14
|
+
/**
|
|
15
|
+
* The conflict's index, from 0.
|
|
16
|
+
*/
|
|
17
|
+
readonly index: number;
|
|
18
|
+
/**
|
|
19
|
+
* How many conflicts the merge has.
|
|
20
|
+
*/
|
|
21
|
+
readonly count: number;
|
|
22
|
+
/**
|
|
23
|
+
* The conflict's base text, or null when the merge has no base.
|
|
24
|
+
*/
|
|
25
|
+
readonly base: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* The conflict's state.
|
|
28
|
+
*/
|
|
29
|
+
readonly state: ConflictState;
|
|
30
|
+
/**
|
|
31
|
+
* The first line the conflict covers in the result, from 0.
|
|
32
|
+
*/
|
|
33
|
+
readonly firstLine: number;
|
|
34
|
+
/**
|
|
35
|
+
* The last line the conflict covers in the result, from 0; the same as
|
|
36
|
+
* {@link ActiveConflict.firstLine} for a conflict with no text.
|
|
37
|
+
*/
|
|
38
|
+
readonly lastLine: number;
|
|
39
|
+
/**
|
|
40
|
+
* Creates the description; {@link MergeEditorComponent} creates one each
|
|
41
|
+
* time the conflict with the caret, or its state, changes.
|
|
42
|
+
*
|
|
43
|
+
* @param index The conflict's index, from 0.
|
|
44
|
+
* @param count How many conflicts the merge has.
|
|
45
|
+
* @param base The conflict's base text, or null when the merge has no base.
|
|
46
|
+
* @param state The conflict's state.
|
|
47
|
+
* @param firstLine The first line the conflict covers in the result, from 0.
|
|
48
|
+
* @param lastLine The last line the conflict covers in the result, from 0.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { ActiveConflict, ConflictState } from "@noldova/code.editor.merge.angular";
|
|
52
|
+
*
|
|
53
|
+
* const conflict = new ActiveConflict(0, 3, "a\n", ConflictState.Unresolved, 4, 4);
|
|
54
|
+
* console.log(`Conflict ${conflict.index + 1} of ${conflict.count}`); // Conflict 1 of 3
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
constructor(index: number, count: number, base: string | null, state: ConflictState, firstLine: number, lastLine: number);
|
|
58
|
+
}
|
|
@@ -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 ActiveConflict {
|
|
9
|
+
index;
|
|
10
|
+
count;
|
|
11
|
+
base;
|
|
12
|
+
state;
|
|
13
|
+
firstLine;
|
|
14
|
+
lastLine;
|
|
15
|
+
constructor(index, count, base, state, firstLine, lastLine) {
|
|
16
|
+
this.index = index;
|
|
17
|
+
this.count = count;
|
|
18
|
+
this.base = base;
|
|
19
|
+
this.state = state;
|
|
20
|
+
this.firstLine = firstLine;
|
|
21
|
+
this.lastLine = lastLine;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -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 { CodeBarAction } from "@noldova/code.editor.angular";
|
|
9
|
+
import type { IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
export declare class ConflictChunk {
|
|
11
|
+
readonly line: number;
|
|
12
|
+
readonly index: number;
|
|
13
|
+
readonly length: number;
|
|
14
|
+
readonly note: string;
|
|
15
|
+
readonly actions: IReadOnlyList<CodeBarAction>;
|
|
16
|
+
constructor(line: number, index: number, length: number, note: string, actions: IReadOnlyList<CodeBarAction>);
|
|
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
|
+
export class ConflictChunk {
|
|
9
|
+
line;
|
|
10
|
+
index;
|
|
11
|
+
length;
|
|
12
|
+
note;
|
|
13
|
+
actions;
|
|
14
|
+
constructor(line, index, length, note, actions) {
|
|
15
|
+
this.line = line;
|
|
16
|
+
this.index = index;
|
|
17
|
+
this.length = length;
|
|
18
|
+
this.note = note;
|
|
19
|
+
this.actions = actions;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -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 type { TextDocument } from "@noldova/code.editor";
|
|
9
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
export declare class ConflictLines {
|
|
11
|
+
static of(document: TextDocument, parts: IReadOnlyList<string>, anchors: IReadOnlyList<string>): IReadOnlyList<number | null>;
|
|
12
|
+
static countOf(text: string): number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export class ConflictLines {
|
|
11
|
+
static of(document, parts, anchors) {
|
|
12
|
+
const text = Resources.lineFeed + document.text();
|
|
13
|
+
const lines = new List();
|
|
14
|
+
let from = 0;
|
|
15
|
+
let index = 0;
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
const found = text.indexOf(Resources.lineFeed + (part === Resources.empty ? anchors.get(index) : part), from);
|
|
18
|
+
lines.add(found < 0 ? null : document.positionAt(found).line);
|
|
19
|
+
from = found < 0 ? from : found + part.length;
|
|
20
|
+
index++;
|
|
21
|
+
}
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
24
|
+
static countOf(text) {
|
|
25
|
+
return text === Resources.empty ? 0 : text.split(Resources.lineFeed).length - (text.endsWith(Resources.lineFeed) ? 1 : 0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { CodeDecorations } from "@noldova/code.editor.angular";
|
|
10
|
+
import { type MergeDocument } from "@noldova/code.editor.merge";
|
|
11
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
12
|
+
import type { ConflictChunk } from "./conflict-chunk.js";
|
|
13
|
+
export declare class MergeMarks {
|
|
14
|
+
static sideOf(chunks: IReadOnlyList<ConflictChunk>, background: string | null): CodeDecorations;
|
|
15
|
+
static resultOf(merge: MergeDocument, editable: boolean): CodeDecorations;
|
|
16
|
+
private static choicesOf;
|
|
17
|
+
private static firstLines;
|
|
18
|
+
private static backgroundOf;
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { CodeBar, CodeBarAction, CodeDecorations, CodeGutterMarker, CodeLineDecoration, CodeSpacer } from "@noldova/code.editor.angular";
|
|
10
|
+
import { ConflictState } from "@noldova/code.editor.merge";
|
|
11
|
+
import { List } from "@noldova/context.collections";
|
|
12
|
+
import { Resources } from "../../resources.js";
|
|
13
|
+
import { ConflictLines } from "./conflict-lines.js";
|
|
14
|
+
export class MergeMarks {
|
|
15
|
+
static sideOf(chunks, background) {
|
|
16
|
+
const lines = Object.isNull(background) ? new List()
|
|
17
|
+
: chunks.select(t => new CodeLineDecoration(t.line, t.length, background)).toList();
|
|
18
|
+
const rows = chunks.select((t) => new CodeBar(String(t.index), t.line, t.note, null, t.actions)).toList();
|
|
19
|
+
return new CodeDecorations(lines, new List(), new List(), rows);
|
|
20
|
+
}
|
|
21
|
+
static resultOf(merge, editable) {
|
|
22
|
+
const lines = new List();
|
|
23
|
+
const markers = new List();
|
|
24
|
+
const rows = new List();
|
|
25
|
+
for (const conflict of merge.conflicts) {
|
|
26
|
+
const state = merge.stateOf(conflict.index);
|
|
27
|
+
const start = merge.document.positionAt(conflict.start);
|
|
28
|
+
const end = merge.document.positionAt(conflict.end);
|
|
29
|
+
if (state === ConflictState.Unresolved)
|
|
30
|
+
rows.add(new CodeBar(String(conflict.index), start.line, Resources.formatOpen(conflict.index + 1), Resources.warningIcon, editable ? MergeMarks.choicesOf(conflict) : new List(), Resources.openBarBackground, Resources.textColor));
|
|
31
|
+
const unresolved = state === ConflictState.Unresolved;
|
|
32
|
+
if (conflict.start === conflict.end) {
|
|
33
|
+
rows.add(new CodeSpacer(start.line, 1, MergeMarks.backgroundOf(state, true) ?? Resources.clearBackground, unresolved ? Resources.conflictSign : null, Resources.warningColor));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const last = end.column === 0 ? end.line - 1 : end.line;
|
|
37
|
+
const split = start.line + MergeMarks.firstLines(conflict, state);
|
|
38
|
+
const firstBackground = MergeMarks.backgroundOf(state, true);
|
|
39
|
+
const secondBackground = MergeMarks.backgroundOf(state, false);
|
|
40
|
+
if (!Object.isNull(firstBackground) && split > start.line)
|
|
41
|
+
lines.add(new CodeLineDecoration(start.line, split - start.line, firstBackground));
|
|
42
|
+
if (!Object.isNull(secondBackground) && last >= split)
|
|
43
|
+
lines.add(new CodeLineDecoration(split, last - split + 1, secondBackground));
|
|
44
|
+
if (unresolved)
|
|
45
|
+
for (let line = start.line; line <= last; line++)
|
|
46
|
+
markers.add(new CodeGutterMarker(line, Resources.conflictSign, Resources.warningColor));
|
|
47
|
+
}
|
|
48
|
+
return new CodeDecorations(lines, new List(), markers, rows);
|
|
49
|
+
}
|
|
50
|
+
static choicesOf(conflict) {
|
|
51
|
+
const choices = new List([new CodeBarAction(Resources.oursAction, Resources.oursChoiceLabel),
|
|
52
|
+
new CodeBarAction(Resources.theirsAction, Resources.theirsChoiceLabel), new CodeBarAction(Resources.bothAction, Resources.bothChoiceLabel)]);
|
|
53
|
+
if (!Object.isNull(conflict.suggestion))
|
|
54
|
+
choices.add(new CodeBarAction(Resources.suggestedAction, Resources.suggestedChoiceLabel, Resources.suggestedIcon));
|
|
55
|
+
return choices;
|
|
56
|
+
}
|
|
57
|
+
static firstLines(conflict, state) {
|
|
58
|
+
switch (state) {
|
|
59
|
+
case ConflictState.BothOursFirst:
|
|
60
|
+
return ConflictLines.countOf(conflict.ours);
|
|
61
|
+
case ConflictState.BothTheirsFirst:
|
|
62
|
+
return ConflictLines.countOf(conflict.theirs);
|
|
63
|
+
default:
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
static backgroundOf(state, first) {
|
|
68
|
+
switch (state) {
|
|
69
|
+
case ConflictState.Unresolved:
|
|
70
|
+
return null;
|
|
71
|
+
case ConflictState.Ours:
|
|
72
|
+
return Resources.oursBackground;
|
|
73
|
+
case ConflictState.Theirs:
|
|
74
|
+
return Resources.theirsBackground;
|
|
75
|
+
case ConflictState.BothOursFirst:
|
|
76
|
+
return first ? Resources.oursBackground : Resources.theirsBackground;
|
|
77
|
+
case ConflictState.BothTheirsFirst:
|
|
78
|
+
return first ? Resources.theirsBackground : Resources.oursBackground;
|
|
79
|
+
default:
|
|
80
|
+
return Resources.mixedBackground;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -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 type { ConflictMarkersException, MergeDocument } from "@noldova/code.editor.merge";
|
|
9
|
+
export declare class MergeOpening {
|
|
10
|
+
readonly merge: MergeDocument | null;
|
|
11
|
+
readonly failure: ConflictMarkersException | null;
|
|
12
|
+
constructor(merge: MergeDocument | null, failure: ConflictMarkersException | null);
|
|
13
|
+
}
|