@gravionlabs/helix-code 0.0.0-stage → 22.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +15 -2
- package/fesm2022/gravionlabs-helix-code-git.mjs +974 -0
- package/fesm2022/gravionlabs-helix-code-git.mjs.map +1 -0
- package/fesm2022/gravionlabs-helix-code.mjs +2822 -0
- package/fesm2022/gravionlabs-helix-code.mjs.map +1 -0
- package/git/package.json +5 -0
- package/package.json +81 -4
- package/types/gravionlabs-helix-code-git.d.ts +334 -0
- package/types/gravionlabs-helix-code.d.ts +604 -0
|
@@ -0,0 +1,2822 @@
|
|
|
1
|
+
import { Decoration, EditorView, GutterMarker, WidgetType, keymap, lineNumberMarkers, lineNumbers } from "@codemirror/view";
|
|
2
|
+
import { HighlightStyle, LanguageDescription, syntaxHighlighting } from "@codemirror/language";
|
|
3
|
+
import { tags } from "@lezer/highlight";
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, InjectionToken, SecurityContext, ViewEncapsulation, afterNextRender, booleanAttribute, computed, effect, forwardRef, inject, input, linkedSignal, model, output, signal, untracked, viewChild } from "@angular/core";
|
|
6
|
+
import { languages } from "@codemirror/language-data";
|
|
7
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
8
|
+
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
|
9
|
+
import { Annotation, Compartment, EditorSelection, EditorState, Facet, RangeSet, StateEffect, StateField } from "@codemirror/state";
|
|
10
|
+
import { MergeView, acceptChunk, getChunks, getOriginalDoc, rejectChunk, uncollapseUnchanged, unifiedMergeView } from "@codemirror/merge";
|
|
11
|
+
import { DomSanitizer } from "@angular/platform-browser";
|
|
12
|
+
function hxCodeTheme() {
|
|
13
|
+
return EditorView.theme({
|
|
14
|
+
"&": {
|
|
15
|
+
color: "var(--h-text-color)",
|
|
16
|
+
backgroundColor: "var(--h-content-background)",
|
|
17
|
+
fontSize: "var(--hx-code-font-size, 0.875rem)"
|
|
18
|
+
},
|
|
19
|
+
"&.cm-focused": { outline: "none" },
|
|
20
|
+
".cm-scroller": { fontFamily: "var(--hx-code-font-family, ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace)" },
|
|
21
|
+
".cm-content": { caretColor: "var(--h-primary-color)" },
|
|
22
|
+
".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--h-primary-color)" },
|
|
23
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "var(--h-highlight-background)" },
|
|
24
|
+
".cm-activeLine": { backgroundColor: "var(--h-content-hover-background)" },
|
|
25
|
+
".cm-selectionMatch": { backgroundColor: "var(--h-highlight-background)" },
|
|
26
|
+
"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": { backgroundColor: "var(--h-highlight-background)" },
|
|
27
|
+
".cm-gutters": {
|
|
28
|
+
color: "var(--h-text-muted-color)",
|
|
29
|
+
backgroundColor: "var(--h-content-background)",
|
|
30
|
+
borderRight: "1px solid var(--h-content-border-color)"
|
|
31
|
+
},
|
|
32
|
+
".cm-activeLineGutter": {
|
|
33
|
+
color: "var(--h-text-color)",
|
|
34
|
+
backgroundColor: "var(--h-content-hover-background)"
|
|
35
|
+
},
|
|
36
|
+
".cm-foldPlaceholder": {
|
|
37
|
+
color: "var(--h-text-muted-color)",
|
|
38
|
+
backgroundColor: "var(--h-content-hover-background)",
|
|
39
|
+
border: "1px solid var(--h-content-border-color)"
|
|
40
|
+
},
|
|
41
|
+
".cm-panels": {
|
|
42
|
+
color: "var(--h-text-color)",
|
|
43
|
+
backgroundColor: "var(--h-content-background)"
|
|
44
|
+
},
|
|
45
|
+
".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--h-content-border-color)" },
|
|
46
|
+
".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--h-content-border-color)" },
|
|
47
|
+
".cm-tooltip": {
|
|
48
|
+
color: "var(--h-overlay-popover-color, var(--h-text-color))",
|
|
49
|
+
backgroundColor: "var(--h-overlay-popover-background, var(--h-content-background))",
|
|
50
|
+
border: "1px solid var(--h-overlay-popover-border-color, var(--h-content-border-color))",
|
|
51
|
+
borderRadius: "var(--h-overlay-popover-border-radius, var(--h-content-border-radius))"
|
|
52
|
+
},
|
|
53
|
+
".cm-tooltip-autocomplete > ul > li[aria-selected]": {
|
|
54
|
+
color: "var(--h-highlight-color)",
|
|
55
|
+
backgroundColor: "var(--h-highlight-background)"
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const HX_CODE_PALETTE = {
|
|
60
|
+
keyword: {
|
|
61
|
+
light: "#6d28d9",
|
|
62
|
+
dark: "#c4b5fd"
|
|
63
|
+
},
|
|
64
|
+
string: {
|
|
65
|
+
light: "#0f766e",
|
|
66
|
+
dark: "#5eead4"
|
|
67
|
+
},
|
|
68
|
+
number: {
|
|
69
|
+
light: "#b45309",
|
|
70
|
+
dark: "#fdba74"
|
|
71
|
+
},
|
|
72
|
+
comment: {
|
|
73
|
+
light: "#667085",
|
|
74
|
+
dark: "#9ca3af"
|
|
75
|
+
},
|
|
76
|
+
function: {
|
|
77
|
+
light: "#1d4ed8",
|
|
78
|
+
dark: "#93c5fd"
|
|
79
|
+
},
|
|
80
|
+
type: {
|
|
81
|
+
light: "#0e7490",
|
|
82
|
+
dark: "#67e8f9"
|
|
83
|
+
},
|
|
84
|
+
property: {
|
|
85
|
+
light: "#0369a1",
|
|
86
|
+
dark: "#7dd3fc"
|
|
87
|
+
},
|
|
88
|
+
operator: {
|
|
89
|
+
light: "#475569",
|
|
90
|
+
dark: "#cbd5e1"
|
|
91
|
+
},
|
|
92
|
+
meta: {
|
|
93
|
+
light: "#4b5563",
|
|
94
|
+
dark: "#9ca3af"
|
|
95
|
+
},
|
|
96
|
+
invalid: {
|
|
97
|
+
light: "#b91c1c",
|
|
98
|
+
dark: "#fca5a5"
|
|
99
|
+
},
|
|
100
|
+
link: {
|
|
101
|
+
light: "#1d4ed8",
|
|
102
|
+
dark: "#93c5fd"
|
|
103
|
+
},
|
|
104
|
+
heading: {
|
|
105
|
+
light: "#1e40af",
|
|
106
|
+
dark: "#bfdbfe"
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const ROLES = Object.keys(HX_CODE_PALETTE);
|
|
110
|
+
function roleColor(role) {
|
|
111
|
+
return `var(--hx-code-${role}, var(--hx-code-default-${role}))`;
|
|
112
|
+
}
|
|
113
|
+
const defaultsTheme = EditorView.baseTheme({
|
|
114
|
+
"&": Object.fromEntries(ROLES.map((r) => [`--hx-code-default-${r}`, HX_CODE_PALETTE[r].light])),
|
|
115
|
+
".app-dark &": Object.fromEntries(ROLES.map((r) => [`--hx-code-default-${r}`, HX_CODE_PALETTE[r].dark]))
|
|
116
|
+
});
|
|
117
|
+
const style = HighlightStyle.define([
|
|
118
|
+
{
|
|
119
|
+
tag: [
|
|
120
|
+
tags.keyword,
|
|
121
|
+
tags.controlKeyword,
|
|
122
|
+
tags.moduleKeyword,
|
|
123
|
+
tags.definitionKeyword
|
|
124
|
+
],
|
|
125
|
+
color: roleColor("keyword")
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
tag: [
|
|
129
|
+
tags.string,
|
|
130
|
+
tags.special(tags.string),
|
|
131
|
+
tags.regexp,
|
|
132
|
+
tags.character
|
|
133
|
+
],
|
|
134
|
+
color: roleColor("string")
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
tag: [
|
|
138
|
+
tags.number,
|
|
139
|
+
tags.bool,
|
|
140
|
+
tags.null,
|
|
141
|
+
tags.atom,
|
|
142
|
+
tags.unit
|
|
143
|
+
],
|
|
144
|
+
color: roleColor("number")
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
tag: [
|
|
148
|
+
tags.comment,
|
|
149
|
+
tags.lineComment,
|
|
150
|
+
tags.blockComment,
|
|
151
|
+
tags.docComment
|
|
152
|
+
],
|
|
153
|
+
color: roleColor("comment"),
|
|
154
|
+
fontStyle: "italic"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
tag: [
|
|
158
|
+
tags.function(tags.variableName),
|
|
159
|
+
tags.function(tags.propertyName),
|
|
160
|
+
tags.macroName,
|
|
161
|
+
tags.labelName
|
|
162
|
+
],
|
|
163
|
+
color: roleColor("function")
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
tag: [
|
|
167
|
+
tags.typeName,
|
|
168
|
+
tags.className,
|
|
169
|
+
tags.namespace,
|
|
170
|
+
tags.tagName
|
|
171
|
+
],
|
|
172
|
+
color: roleColor("type")
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
tag: [
|
|
176
|
+
tags.propertyName,
|
|
177
|
+
tags.attributeName,
|
|
178
|
+
tags.definition(tags.variableName)
|
|
179
|
+
],
|
|
180
|
+
color: roleColor("property")
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
tag: [
|
|
184
|
+
tags.operator,
|
|
185
|
+
tags.punctuation,
|
|
186
|
+
tags.separator,
|
|
187
|
+
tags.bracket
|
|
188
|
+
],
|
|
189
|
+
color: roleColor("operator")
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
tag: [
|
|
193
|
+
tags.meta,
|
|
194
|
+
tags.processingInstruction,
|
|
195
|
+
tags.annotation,
|
|
196
|
+
tags.documentMeta
|
|
197
|
+
],
|
|
198
|
+
color: roleColor("meta")
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
tag: tags.invalid,
|
|
202
|
+
color: roleColor("invalid")
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
tag: [tags.link, tags.url],
|
|
206
|
+
color: roleColor("link"),
|
|
207
|
+
textDecoration: "underline"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
tag: tags.heading,
|
|
211
|
+
color: roleColor("heading"),
|
|
212
|
+
fontWeight: "600"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
tag: tags.emphasis,
|
|
216
|
+
fontStyle: "italic"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
tag: tags.strong,
|
|
220
|
+
fontWeight: "600"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
tag: tags.strikethrough,
|
|
224
|
+
textDecoration: "line-through"
|
|
225
|
+
}
|
|
226
|
+
]);
|
|
227
|
+
function hxCodeHighlight() {
|
|
228
|
+
return [defaultsTheme, syntaxHighlighting(style)];
|
|
229
|
+
}
|
|
230
|
+
const HX_CODE_LANGUAGES = new InjectionToken("HX_CODE_LANGUAGES", {
|
|
231
|
+
providedIn: "root",
|
|
232
|
+
factory: () => languages
|
|
233
|
+
});
|
|
234
|
+
function hxLanguageFor(path, languages$1 = languages) {
|
|
235
|
+
const name = path.split(/[\\/]/).pop() ?? path;
|
|
236
|
+
if (!name) return null;
|
|
237
|
+
return LanguageDescription.matchFilename(languages$1, name);
|
|
238
|
+
}
|
|
239
|
+
async function hxLoadLanguage(path, languages$2 = languages) {
|
|
240
|
+
const description = hxLanguageFor(path, languages$2);
|
|
241
|
+
if (!description) return null;
|
|
242
|
+
try {
|
|
243
|
+
return await description.load();
|
|
244
|
+
} catch {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const external = Annotation.define();
|
|
249
|
+
var HxCodeEditor = class HxCodeEditor {
|
|
250
|
+
#languages = inject(HX_CODE_LANGUAGES);
|
|
251
|
+
value = model("", ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
|
|
252
|
+
disabled = input(false, {
|
|
253
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
254
|
+
transform: booleanAttribute
|
|
255
|
+
});
|
|
256
|
+
invalid = input(false, {
|
|
257
|
+
...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
|
|
258
|
+
transform: booleanAttribute
|
|
259
|
+
});
|
|
260
|
+
touch = output();
|
|
261
|
+
path = input("", ...ngDevMode ? [{ debugName: "path" }] : /* istanbul ignore next */ []);
|
|
262
|
+
readOnly = input(false, {
|
|
263
|
+
...ngDevMode ? { debugName: "readOnly" } : /* istanbul ignore next */ {},
|
|
264
|
+
transform: booleanAttribute
|
|
265
|
+
});
|
|
266
|
+
lineNumbers = input(true, {
|
|
267
|
+
...ngDevMode ? { debugName: "lineNumbers" } : /* istanbul ignore next */ {},
|
|
268
|
+
transform: booleanAttribute
|
|
269
|
+
});
|
|
270
|
+
lineWrapping = input(false, {
|
|
271
|
+
...ngDevMode ? { debugName: "lineWrapping" } : /* istanbul ignore next */ {},
|
|
272
|
+
transform: booleanAttribute
|
|
273
|
+
});
|
|
274
|
+
extensions = input([], ...ngDevMode ? [{ debugName: "extensions" }] : /* istanbul ignore next */ []);
|
|
275
|
+
ariaLabel = input(null, {
|
|
276
|
+
...ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {},
|
|
277
|
+
alias: "aria-label"
|
|
278
|
+
});
|
|
279
|
+
ariaLabelledby = input(null, {
|
|
280
|
+
...ngDevMode ? { debugName: "ariaLabelledby" } : /* istanbul ignore next */ {},
|
|
281
|
+
alias: "aria-labelledby"
|
|
282
|
+
});
|
|
283
|
+
#view = signal(null, ...ngDevMode ? [{ debugName: "#view" }] : /* istanbul ignore next */ []);
|
|
284
|
+
view = this.#view.asReadonly();
|
|
285
|
+
container = viewChild.required("container", ...ngDevMode ? [{ debugName: "container" }] : /* istanbul ignore next */ []);
|
|
286
|
+
#written = signal(null, ...ngDevMode ? [{ debugName: "#written" }] : /* istanbul ignore next */ []);
|
|
287
|
+
#cvaDisabled = signal(false, ...ngDevMode ? [{ debugName: "#cvaDisabled" }] : /* istanbul ignore next */ []);
|
|
288
|
+
isDisabled = () => this.disabled() || this.#cvaDisabled();
|
|
289
|
+
#readOnly = new Compartment();
|
|
290
|
+
#lineNumbers = new Compartment();
|
|
291
|
+
#lineWrapping = new Compartment();
|
|
292
|
+
#language = new Compartment();
|
|
293
|
+
#userExtensions = new Compartment();
|
|
294
|
+
#labels = new Compartment();
|
|
295
|
+
#generation = 0;
|
|
296
|
+
#onChange = () => {};
|
|
297
|
+
#onTouched = () => {};
|
|
298
|
+
constructor() {
|
|
299
|
+
afterNextRender(() => {
|
|
300
|
+
const view = new EditorView({
|
|
301
|
+
parent: this.container().nativeElement,
|
|
302
|
+
state: EditorState.create({
|
|
303
|
+
doc: untracked(() => this.#written()?.text ?? this.value()),
|
|
304
|
+
extensions: [
|
|
305
|
+
hxCodeTheme(),
|
|
306
|
+
hxCodeHighlight(),
|
|
307
|
+
history(),
|
|
308
|
+
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
309
|
+
this.#readOnly.of(this.#readOnlyExtension()),
|
|
310
|
+
this.#lineNumbers.of(this.lineNumbers() ? lineNumbers() : []),
|
|
311
|
+
this.#lineWrapping.of(this.lineWrapping() ? EditorView.lineWrapping : []),
|
|
312
|
+
this.#language.of([]),
|
|
313
|
+
this.#userExtensions.of([...this.extensions()]),
|
|
314
|
+
this.#labels.of(this.#labelExtension()),
|
|
315
|
+
EditorView.updateListener.of((update) => {
|
|
316
|
+
if (!update.docChanged) return;
|
|
317
|
+
if (update.transactions.some((tr) => tr.annotation(external))) return;
|
|
318
|
+
const text = update.state.doc.toString();
|
|
319
|
+
this.value.set(text);
|
|
320
|
+
this.#onChange(text);
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
})
|
|
324
|
+
});
|
|
325
|
+
this.#view.set(view);
|
|
326
|
+
});
|
|
327
|
+
inject(DestroyRef).onDestroy(() => {
|
|
328
|
+
this.#generation++;
|
|
329
|
+
this.#view()?.destroy();
|
|
330
|
+
});
|
|
331
|
+
effect(() => this.#setDocument(this.value() ?? ""));
|
|
332
|
+
effect(() => {
|
|
333
|
+
const written = this.#written();
|
|
334
|
+
if (written) this.#setDocument(written.text);
|
|
335
|
+
});
|
|
336
|
+
effect(() => {
|
|
337
|
+
const view = this.#view();
|
|
338
|
+
if (!view) return;
|
|
339
|
+
view.dispatch({ effects: this.#readOnly.reconfigure(this.#readOnlyExtension()) });
|
|
340
|
+
});
|
|
341
|
+
effect(() => {
|
|
342
|
+
this.#view()?.dispatch({ effects: this.#lineNumbers.reconfigure(this.lineNumbers() ? lineNumbers() : []) });
|
|
343
|
+
});
|
|
344
|
+
effect(() => {
|
|
345
|
+
this.#view()?.dispatch({ effects: this.#lineWrapping.reconfigure(this.lineWrapping() ? EditorView.lineWrapping : []) });
|
|
346
|
+
});
|
|
347
|
+
effect(() => {
|
|
348
|
+
this.#view()?.dispatch({ effects: this.#userExtensions.reconfigure([...this.extensions()]) });
|
|
349
|
+
});
|
|
350
|
+
effect(() => {
|
|
351
|
+
this.#view()?.dispatch({ effects: this.#labels.reconfigure(this.#labelExtension()) });
|
|
352
|
+
});
|
|
353
|
+
effect(() => {
|
|
354
|
+
const view = this.#view();
|
|
355
|
+
const path = this.path();
|
|
356
|
+
if (!view) return;
|
|
357
|
+
const generation = ++this.#generation;
|
|
358
|
+
hxLoadLanguage(path, this.#languages).then((support) => {
|
|
359
|
+
if (generation !== this.#generation) return;
|
|
360
|
+
view.dispatch({ effects: this.#language.reconfigure(support ?? []) });
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
focus() {
|
|
365
|
+
this.#view()?.focus();
|
|
366
|
+
}
|
|
367
|
+
#setDocument(text) {
|
|
368
|
+
const view = this.#view();
|
|
369
|
+
if (!view || view.state.doc.toString() === text) return;
|
|
370
|
+
view.dispatch({
|
|
371
|
+
changes: {
|
|
372
|
+
from: 0,
|
|
373
|
+
to: view.state.doc.length,
|
|
374
|
+
insert: text
|
|
375
|
+
},
|
|
376
|
+
annotations: external.of(true)
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
#readOnlyExtension() {
|
|
380
|
+
const locked = this.readOnly() || this.isDisabled();
|
|
381
|
+
return [EditorState.readOnly.of(locked), EditorView.editable.of(!this.isDisabled())];
|
|
382
|
+
}
|
|
383
|
+
#labelExtension() {
|
|
384
|
+
const attributes = {};
|
|
385
|
+
const label = this.ariaLabel();
|
|
386
|
+
const labelledby = this.ariaLabelledby();
|
|
387
|
+
if (label) attributes["aria-label"] = label;
|
|
388
|
+
if (labelledby) attributes["aria-labelledby"] = labelledby;
|
|
389
|
+
return EditorView.contentAttributes.of(attributes);
|
|
390
|
+
}
|
|
391
|
+
onFocusOut() {
|
|
392
|
+
this.touch.emit();
|
|
393
|
+
this.#onTouched();
|
|
394
|
+
}
|
|
395
|
+
writeValue(value) {
|
|
396
|
+
this.#written.set({ text: value ?? "" });
|
|
397
|
+
}
|
|
398
|
+
registerOnChange(fn) {
|
|
399
|
+
this.#onChange = fn;
|
|
400
|
+
}
|
|
401
|
+
registerOnTouched(fn) {
|
|
402
|
+
this.#onTouched = fn;
|
|
403
|
+
}
|
|
404
|
+
setDisabledState(disabled) {
|
|
405
|
+
this.#cvaDisabled.set(disabled);
|
|
406
|
+
}
|
|
407
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
408
|
+
minVersion: "12.0.0",
|
|
409
|
+
version: "22.3.0",
|
|
410
|
+
ngImport: i0,
|
|
411
|
+
type: HxCodeEditor,
|
|
412
|
+
deps: [],
|
|
413
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
414
|
+
});
|
|
415
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
416
|
+
minVersion: "17.2.0",
|
|
417
|
+
version: "22.3.0",
|
|
418
|
+
type: HxCodeEditor,
|
|
419
|
+
isStandalone: true,
|
|
420
|
+
selector: "hx-code-editor",
|
|
421
|
+
inputs: {
|
|
422
|
+
value: {
|
|
423
|
+
classPropertyName: "value",
|
|
424
|
+
publicName: "value",
|
|
425
|
+
isSignal: true,
|
|
426
|
+
isRequired: false,
|
|
427
|
+
transformFunction: null
|
|
428
|
+
},
|
|
429
|
+
disabled: {
|
|
430
|
+
classPropertyName: "disabled",
|
|
431
|
+
publicName: "disabled",
|
|
432
|
+
isSignal: true,
|
|
433
|
+
isRequired: false,
|
|
434
|
+
transformFunction: null
|
|
435
|
+
},
|
|
436
|
+
invalid: {
|
|
437
|
+
classPropertyName: "invalid",
|
|
438
|
+
publicName: "invalid",
|
|
439
|
+
isSignal: true,
|
|
440
|
+
isRequired: false,
|
|
441
|
+
transformFunction: null
|
|
442
|
+
},
|
|
443
|
+
path: {
|
|
444
|
+
classPropertyName: "path",
|
|
445
|
+
publicName: "path",
|
|
446
|
+
isSignal: true,
|
|
447
|
+
isRequired: false,
|
|
448
|
+
transformFunction: null
|
|
449
|
+
},
|
|
450
|
+
readOnly: {
|
|
451
|
+
classPropertyName: "readOnly",
|
|
452
|
+
publicName: "readOnly",
|
|
453
|
+
isSignal: true,
|
|
454
|
+
isRequired: false,
|
|
455
|
+
transformFunction: null
|
|
456
|
+
},
|
|
457
|
+
lineNumbers: {
|
|
458
|
+
classPropertyName: "lineNumbers",
|
|
459
|
+
publicName: "lineNumbers",
|
|
460
|
+
isSignal: true,
|
|
461
|
+
isRequired: false,
|
|
462
|
+
transformFunction: null
|
|
463
|
+
},
|
|
464
|
+
lineWrapping: {
|
|
465
|
+
classPropertyName: "lineWrapping",
|
|
466
|
+
publicName: "lineWrapping",
|
|
467
|
+
isSignal: true,
|
|
468
|
+
isRequired: false,
|
|
469
|
+
transformFunction: null
|
|
470
|
+
},
|
|
471
|
+
extensions: {
|
|
472
|
+
classPropertyName: "extensions",
|
|
473
|
+
publicName: "extensions",
|
|
474
|
+
isSignal: true,
|
|
475
|
+
isRequired: false,
|
|
476
|
+
transformFunction: null
|
|
477
|
+
},
|
|
478
|
+
ariaLabel: {
|
|
479
|
+
classPropertyName: "ariaLabel",
|
|
480
|
+
publicName: "aria-label",
|
|
481
|
+
isSignal: true,
|
|
482
|
+
isRequired: false,
|
|
483
|
+
transformFunction: null
|
|
484
|
+
},
|
|
485
|
+
ariaLabelledby: {
|
|
486
|
+
classPropertyName: "ariaLabelledby",
|
|
487
|
+
publicName: "aria-labelledby",
|
|
488
|
+
isSignal: true,
|
|
489
|
+
isRequired: false,
|
|
490
|
+
transformFunction: null
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
outputs: {
|
|
494
|
+
value: "valueChange",
|
|
495
|
+
touch: "touch"
|
|
496
|
+
},
|
|
497
|
+
host: {
|
|
498
|
+
listeners: { "focusout": "onFocusOut()" },
|
|
499
|
+
properties: {
|
|
500
|
+
"class.hx-code-editor-invalid": "invalid()",
|
|
501
|
+
"class.hx-code-editor-disabled": "isDisabled()",
|
|
502
|
+
"attr.aria-label": "null",
|
|
503
|
+
"attr.aria-labelledby": "null"
|
|
504
|
+
},
|
|
505
|
+
classAttribute: "hx-code-editor"
|
|
506
|
+
},
|
|
507
|
+
providers: [{
|
|
508
|
+
provide: NG_VALUE_ACCESSOR,
|
|
509
|
+
useExisting: forwardRef(() => HxCodeEditor),
|
|
510
|
+
multi: true
|
|
511
|
+
}],
|
|
512
|
+
viewQueries: [{
|
|
513
|
+
propertyName: "container",
|
|
514
|
+
first: true,
|
|
515
|
+
predicate: ["container"],
|
|
516
|
+
descendants: true,
|
|
517
|
+
isSignal: true
|
|
518
|
+
}],
|
|
519
|
+
ngImport: i0,
|
|
520
|
+
template: "<div #container class=\"hx-code-editor-container\"></div>\n",
|
|
521
|
+
styles: [":host{display:block;min-height:6rem;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px);overflow:hidden}:host(.hx-code-editor-invalid){border-color:var(--h-form-field-invalid-border-color)}:host(.hx-code-editor-disabled){opacity:.6}.hx-code-editor-container{height:100%}.hx-code-editor-container ::ng-deep .cm-editor{height:100%}.hx-code-editor-container ::ng-deep .cm-editor.cm-focused{outline:2px solid var(--h-primary-color);outline-offset:-2px}\n"],
|
|
522
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
526
|
+
minVersion: "12.0.0",
|
|
527
|
+
version: "22.3.0",
|
|
528
|
+
ngImport: i0,
|
|
529
|
+
type: HxCodeEditor,
|
|
530
|
+
decorators: [{
|
|
531
|
+
type: Component,
|
|
532
|
+
args: [{
|
|
533
|
+
selector: "hx-code-editor",
|
|
534
|
+
encapsulation: ViewEncapsulation.Emulated,
|
|
535
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
536
|
+
providers: [{
|
|
537
|
+
provide: NG_VALUE_ACCESSOR,
|
|
538
|
+
useExisting: forwardRef(() => HxCodeEditor),
|
|
539
|
+
multi: true
|
|
540
|
+
}],
|
|
541
|
+
host: {
|
|
542
|
+
class: "hx-code-editor",
|
|
543
|
+
"[class.hx-code-editor-invalid]": "invalid()",
|
|
544
|
+
"[class.hx-code-editor-disabled]": "isDisabled()",
|
|
545
|
+
"[attr.aria-label]": "null",
|
|
546
|
+
"[attr.aria-labelledby]": "null",
|
|
547
|
+
"(focusout)": "onFocusOut()"
|
|
548
|
+
},
|
|
549
|
+
template: "<div #container class=\"hx-code-editor-container\"></div>\n",
|
|
550
|
+
styles: [":host{display:block;min-height:6rem;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px);overflow:hidden}:host(.hx-code-editor-invalid){border-color:var(--h-form-field-invalid-border-color)}:host(.hx-code-editor-disabled){opacity:.6}.hx-code-editor-container{height:100%}.hx-code-editor-container ::ng-deep .cm-editor{height:100%}.hx-code-editor-container ::ng-deep .cm-editor.cm-focused{outline:2px solid var(--h-primary-color);outline-offset:-2px}\n"]
|
|
551
|
+
}]
|
|
552
|
+
}],
|
|
553
|
+
ctorParameters: () => [],
|
|
554
|
+
propDecorators: {
|
|
555
|
+
value: [{
|
|
556
|
+
type: i0.Input,
|
|
557
|
+
args: [{
|
|
558
|
+
isSignal: true,
|
|
559
|
+
alias: "value",
|
|
560
|
+
required: false
|
|
561
|
+
}]
|
|
562
|
+
}, {
|
|
563
|
+
type: i0.Output,
|
|
564
|
+
args: ["valueChange"]
|
|
565
|
+
}],
|
|
566
|
+
disabled: [{
|
|
567
|
+
type: i0.Input,
|
|
568
|
+
args: [{
|
|
569
|
+
isSignal: true,
|
|
570
|
+
alias: "disabled",
|
|
571
|
+
required: false
|
|
572
|
+
}]
|
|
573
|
+
}],
|
|
574
|
+
invalid: [{
|
|
575
|
+
type: i0.Input,
|
|
576
|
+
args: [{
|
|
577
|
+
isSignal: true,
|
|
578
|
+
alias: "invalid",
|
|
579
|
+
required: false
|
|
580
|
+
}]
|
|
581
|
+
}],
|
|
582
|
+
touch: [{
|
|
583
|
+
type: i0.Output,
|
|
584
|
+
args: ["touch"]
|
|
585
|
+
}],
|
|
586
|
+
path: [{
|
|
587
|
+
type: i0.Input,
|
|
588
|
+
args: [{
|
|
589
|
+
isSignal: true,
|
|
590
|
+
alias: "path",
|
|
591
|
+
required: false
|
|
592
|
+
}]
|
|
593
|
+
}],
|
|
594
|
+
readOnly: [{
|
|
595
|
+
type: i0.Input,
|
|
596
|
+
args: [{
|
|
597
|
+
isSignal: true,
|
|
598
|
+
alias: "readOnly",
|
|
599
|
+
required: false
|
|
600
|
+
}]
|
|
601
|
+
}],
|
|
602
|
+
lineNumbers: [{
|
|
603
|
+
type: i0.Input,
|
|
604
|
+
args: [{
|
|
605
|
+
isSignal: true,
|
|
606
|
+
alias: "lineNumbers",
|
|
607
|
+
required: false
|
|
608
|
+
}]
|
|
609
|
+
}],
|
|
610
|
+
lineWrapping: [{
|
|
611
|
+
type: i0.Input,
|
|
612
|
+
args: [{
|
|
613
|
+
isSignal: true,
|
|
614
|
+
alias: "lineWrapping",
|
|
615
|
+
required: false
|
|
616
|
+
}]
|
|
617
|
+
}],
|
|
618
|
+
extensions: [{
|
|
619
|
+
type: i0.Input,
|
|
620
|
+
args: [{
|
|
621
|
+
isSignal: true,
|
|
622
|
+
alias: "extensions",
|
|
623
|
+
required: false
|
|
624
|
+
}]
|
|
625
|
+
}],
|
|
626
|
+
ariaLabel: [{
|
|
627
|
+
type: i0.Input,
|
|
628
|
+
args: [{
|
|
629
|
+
isSignal: true,
|
|
630
|
+
alias: "aria-label",
|
|
631
|
+
required: false
|
|
632
|
+
}]
|
|
633
|
+
}],
|
|
634
|
+
ariaLabelledby: [{
|
|
635
|
+
type: i0.Input,
|
|
636
|
+
args: [{
|
|
637
|
+
isSignal: true,
|
|
638
|
+
alias: "aria-labelledby",
|
|
639
|
+
required: false
|
|
640
|
+
}]
|
|
641
|
+
}],
|
|
642
|
+
container: [{
|
|
643
|
+
type: i0.ViewChild,
|
|
644
|
+
args: ["container", { isSignal: true }]
|
|
645
|
+
}]
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
const setComments = StateEffect.define();
|
|
649
|
+
const setDraft = StateEffect.define();
|
|
650
|
+
const handlersFacet$2 = Facet.define({ combine: (values) => values[0] ?? null });
|
|
651
|
+
const formatTime = (time) => {
|
|
652
|
+
if (!time) return "";
|
|
653
|
+
const date = new Date(time);
|
|
654
|
+
return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
|
|
655
|
+
};
|
|
656
|
+
const rangeLabel$2 = (start, end) => start === end ? `line ${start}` : `lines ${start}-${end}`;
|
|
657
|
+
var CommentBox = class extends WidgetType {
|
|
658
|
+
placed;
|
|
659
|
+
constructor(placed) {
|
|
660
|
+
super();
|
|
661
|
+
this.placed = placed;
|
|
662
|
+
}
|
|
663
|
+
eq(other) {
|
|
664
|
+
const a = this.placed;
|
|
665
|
+
const b = other.placed.comment;
|
|
666
|
+
const c = a.comment;
|
|
667
|
+
return c.id === b.id && c.text === b.text && c.author === b.author && c.time === b.time && c.side === b.side && c.startLine === b.startLine && c.endLine === b.endLine && a.end === other.placed.end;
|
|
668
|
+
}
|
|
669
|
+
toDOM() {
|
|
670
|
+
const c = this.placed.comment;
|
|
671
|
+
const box = document.createElement("div");
|
|
672
|
+
box.className = "cm-comment-box";
|
|
673
|
+
box.setAttribute("role", "group");
|
|
674
|
+
box.setAttribute("aria-label", `Comment on ${rangeLabel$2(c.startLine, c.endLine)}`);
|
|
675
|
+
const head = document.createElement("div");
|
|
676
|
+
head.className = "cm-comment-range";
|
|
677
|
+
head.textContent = [...[
|
|
678
|
+
c.author,
|
|
679
|
+
c.side === "original" ? "old" : "",
|
|
680
|
+
rangeLabel$2(c.startLine, c.endLine)
|
|
681
|
+
].filter(Boolean), formatTime(c.time)].filter(Boolean).join(" · ");
|
|
682
|
+
const text = document.createElement("div");
|
|
683
|
+
text.className = "cm-comment-text";
|
|
684
|
+
text.textContent = c.text;
|
|
685
|
+
box.append(head, text);
|
|
686
|
+
return box;
|
|
687
|
+
}
|
|
688
|
+
ignoreEvent() {
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var DraftBox = class extends WidgetType {
|
|
693
|
+
draft;
|
|
694
|
+
constructor(draft) {
|
|
695
|
+
super();
|
|
696
|
+
this.draft = draft;
|
|
697
|
+
}
|
|
698
|
+
eq(other) {
|
|
699
|
+
return other.draft.start === this.draft.start && other.draft.end === this.draft.end;
|
|
700
|
+
}
|
|
701
|
+
toDOM(view) {
|
|
702
|
+
const { start, end, text } = this.draft;
|
|
703
|
+
const close = (save, value) => closeDraft(view, save, value);
|
|
704
|
+
const box = document.createElement("div");
|
|
705
|
+
box.className = "cm-comment-box cm-comment-draft";
|
|
706
|
+
const input = document.createElement("textarea");
|
|
707
|
+
input.className = "cm-comment-input";
|
|
708
|
+
input.rows = 3;
|
|
709
|
+
input.value = text;
|
|
710
|
+
input.placeholder = `Comment on ${rangeLabel$2(start, end)}`;
|
|
711
|
+
input.setAttribute("aria-label", input.placeholder);
|
|
712
|
+
const save = document.createElement("button");
|
|
713
|
+
save.type = "button";
|
|
714
|
+
save.className = "cm-comment-save";
|
|
715
|
+
save.textContent = "Add comment";
|
|
716
|
+
save.disabled = !input.value.trim();
|
|
717
|
+
const cancel = document.createElement("button");
|
|
718
|
+
cancel.type = "button";
|
|
719
|
+
cancel.className = "cm-comment-cancel";
|
|
720
|
+
cancel.textContent = "Cancel";
|
|
721
|
+
const submit = () => {
|
|
722
|
+
if (input.value.trim()) close(true, input.value);
|
|
723
|
+
};
|
|
724
|
+
save.addEventListener("click", submit);
|
|
725
|
+
cancel.addEventListener("click", () => close(false, ""));
|
|
726
|
+
input.addEventListener("input", () => {
|
|
727
|
+
this.draft.text = input.value;
|
|
728
|
+
save.disabled = !input.value.trim();
|
|
729
|
+
});
|
|
730
|
+
input.addEventListener("keydown", (event) => {
|
|
731
|
+
if (event.key === "Escape") close(false, "");
|
|
732
|
+
else if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) submit();
|
|
733
|
+
else return;
|
|
734
|
+
event.preventDefault();
|
|
735
|
+
event.stopPropagation();
|
|
736
|
+
});
|
|
737
|
+
const actions = document.createElement("div");
|
|
738
|
+
actions.className = "cm-comment-actions";
|
|
739
|
+
actions.append(save, cancel);
|
|
740
|
+
box.append(input, actions);
|
|
741
|
+
queueMicrotask(() => input.focus());
|
|
742
|
+
return box;
|
|
743
|
+
}
|
|
744
|
+
ignoreEvent() {
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
const closeDraft = (view, save, text) => {
|
|
749
|
+
const draft = view.state.field(field$2).draft;
|
|
750
|
+
if (!draft) return;
|
|
751
|
+
view.dispatch({ effects: setDraft.of(null) });
|
|
752
|
+
if (save) view.state.facet(handlersFacet$2)?.saved(view, draft.start, draft.end, text);
|
|
753
|
+
view.focus();
|
|
754
|
+
};
|
|
755
|
+
const field$2 = StateField.define({
|
|
756
|
+
create: () => ({
|
|
757
|
+
comments: [],
|
|
758
|
+
draft: null,
|
|
759
|
+
decorations: Decoration.none
|
|
760
|
+
}),
|
|
761
|
+
update(value, tr) {
|
|
762
|
+
let { comments, draft } = value;
|
|
763
|
+
let changed = false;
|
|
764
|
+
for (const effect of tr.effects) if (effect.is(setComments)) {
|
|
765
|
+
comments = effect.value;
|
|
766
|
+
changed = true;
|
|
767
|
+
} else if (effect.is(setDraft)) {
|
|
768
|
+
draft = effect.value;
|
|
769
|
+
changed = true;
|
|
770
|
+
}
|
|
771
|
+
if (!changed) return value;
|
|
772
|
+
return {
|
|
773
|
+
comments,
|
|
774
|
+
draft,
|
|
775
|
+
decorations: decorate$2(tr.state.doc, comments, draft)
|
|
776
|
+
};
|
|
777
|
+
},
|
|
778
|
+
provide: (f) => EditorView.decorations.from(f, (v) => v.decorations)
|
|
779
|
+
});
|
|
780
|
+
function decorate$2(doc, comments, draft) {
|
|
781
|
+
const ranges = [];
|
|
782
|
+
const place = (start, end, widget, mark) => {
|
|
783
|
+
if (start < 1 || end < start || end > doc.lines) return;
|
|
784
|
+
if (mark) for (let n = start; n <= end; n++) ranges.push(Decoration.line({ class: "cm-commented-line" }).range(doc.line(n).from));
|
|
785
|
+
ranges.push(Decoration.widget({
|
|
786
|
+
widget,
|
|
787
|
+
block: true,
|
|
788
|
+
side: 3
|
|
789
|
+
}).range(doc.line(end).to));
|
|
790
|
+
};
|
|
791
|
+
for (const c of comments) place(c.start, c.end, new CommentBox(c), c.mark);
|
|
792
|
+
if (draft) {
|
|
793
|
+
place(draft.start, draft.end, new DraftBox(draft), false);
|
|
794
|
+
for (let n = draft.start; n <= draft.end && n <= doc.lines; n++) ranges.push(Decoration.line({ class: "cm-draft-line" }).range(doc.line(n).from));
|
|
795
|
+
}
|
|
796
|
+
return Decoration.set(ranges, true);
|
|
797
|
+
}
|
|
798
|
+
function showComments(view, comments) {
|
|
799
|
+
view.dispatch({ effects: setComments.of(comments) });
|
|
800
|
+
}
|
|
801
|
+
function discardDraft(view) {
|
|
802
|
+
if (view.state.field(field$2, false)?.draft) view.dispatch({ effects: setDraft.of(null) });
|
|
803
|
+
}
|
|
804
|
+
function quoteOf(view, start, end) {
|
|
805
|
+
const doc = view.state.doc;
|
|
806
|
+
return doc.sliceString(doc.line(start).from, doc.line(end).to);
|
|
807
|
+
}
|
|
808
|
+
function openDraft(view, line, extend) {
|
|
809
|
+
const state = view.state.field(field$2, false);
|
|
810
|
+
if (!state) return false;
|
|
811
|
+
const doc = view.state.doc;
|
|
812
|
+
if (line < 1 || line > doc.lines) return false;
|
|
813
|
+
const old = state.draft;
|
|
814
|
+
const textarea = view.dom.querySelector(".cm-comment-input");
|
|
815
|
+
const text = textarea ? textarea.value : old?.text ?? "";
|
|
816
|
+
const anchor = extend && old ? old.anchor : line;
|
|
817
|
+
const draft = {
|
|
818
|
+
start: Math.min(anchor, line),
|
|
819
|
+
end: Math.max(anchor, line),
|
|
820
|
+
anchor,
|
|
821
|
+
text: old ? text : ""
|
|
822
|
+
};
|
|
823
|
+
view.dispatch({ effects: setDraft.of(draft) });
|
|
824
|
+
if (!old) view.state.facet(handlersFacet$2)?.opened(view);
|
|
825
|
+
return true;
|
|
826
|
+
}
|
|
827
|
+
function openCommentDraft(view) {
|
|
828
|
+
const line = view.state.doc.lineAt(view.state.selection.main.head).number;
|
|
829
|
+
return openDraft(view, line, false);
|
|
830
|
+
}
|
|
831
|
+
function commentExtension(handlers) {
|
|
832
|
+
return [
|
|
833
|
+
handlersFacet$2.of(handlers),
|
|
834
|
+
field$2,
|
|
835
|
+
lineNumbers({ domEventHandlers: { mousedown(view, block, event) {
|
|
836
|
+
const label = event.target.closest(".cm-gutterElement")?.textContent;
|
|
837
|
+
openDraft(view, (/^\d+$/.test(label ?? "") ? Number(label) : 0) || view.state.doc.lineAt(block.from).number, event.shiftKey);
|
|
838
|
+
event.preventDefault();
|
|
839
|
+
return true;
|
|
840
|
+
} } }),
|
|
841
|
+
EditorView.baseTheme({
|
|
842
|
+
".cm-lineNumbers .cm-gutterElement": { cursor: "pointer" },
|
|
843
|
+
".cm-commented-line": { backgroundColor: "var(--h-highlight-background)" },
|
|
844
|
+
".cm-draft-line": { backgroundColor: "var(--h-highlight-focus-background)" },
|
|
845
|
+
".cm-comment-box": {
|
|
846
|
+
margin: "4px 8px 4px 48px",
|
|
847
|
+
padding: "6px 8px",
|
|
848
|
+
border: "1px solid var(--h-content-border-color)",
|
|
849
|
+
borderLeft: "3px solid var(--h-primary-color)",
|
|
850
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
851
|
+
backgroundColor: "var(--h-content-background)",
|
|
852
|
+
color: "var(--h-text-color)",
|
|
853
|
+
fontFamily: "inherit"
|
|
854
|
+
},
|
|
855
|
+
".cm-comment-range": {
|
|
856
|
+
color: "var(--h-text-muted-color)",
|
|
857
|
+
fontSize: "0.75em"
|
|
858
|
+
},
|
|
859
|
+
".cm-comment-text": { whiteSpace: "pre-wrap" },
|
|
860
|
+
".cm-comment-input": {
|
|
861
|
+
display: "block",
|
|
862
|
+
width: "100%",
|
|
863
|
+
boxSizing: "border-box",
|
|
864
|
+
font: "inherit",
|
|
865
|
+
color: "inherit",
|
|
866
|
+
background: "transparent",
|
|
867
|
+
border: "1px solid var(--h-content-border-color)",
|
|
868
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
869
|
+
resize: "vertical"
|
|
870
|
+
},
|
|
871
|
+
".cm-comment-input:focus-visible, .cm-comment-actions button:focus-visible": {
|
|
872
|
+
outline: "2px solid var(--h-primary-color)",
|
|
873
|
+
outlineOffset: "1px"
|
|
874
|
+
},
|
|
875
|
+
".cm-comment-actions": {
|
|
876
|
+
display: "flex",
|
|
877
|
+
gap: "6px",
|
|
878
|
+
marginTop: "6px"
|
|
879
|
+
},
|
|
880
|
+
".cm-comment-actions button": {
|
|
881
|
+
font: "inherit",
|
|
882
|
+
color: "inherit",
|
|
883
|
+
background: "transparent",
|
|
884
|
+
border: "1px solid var(--h-content-border-color)",
|
|
885
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
886
|
+
padding: "2px 10px",
|
|
887
|
+
cursor: "pointer"
|
|
888
|
+
},
|
|
889
|
+
".cm-comment-actions button.cm-comment-save": {
|
|
890
|
+
background: "var(--h-primary-color)",
|
|
891
|
+
borderColor: "var(--h-primary-color)",
|
|
892
|
+
color: "var(--h-primary-contrast-color)"
|
|
893
|
+
},
|
|
894
|
+
".cm-comment-actions button:disabled": {
|
|
895
|
+
opacity: "0.6",
|
|
896
|
+
cursor: "default"
|
|
897
|
+
}
|
|
898
|
+
})
|
|
899
|
+
];
|
|
900
|
+
}
|
|
901
|
+
const setFindings = StateEffect.define();
|
|
902
|
+
const handlersFacet$1 = Facet.define({ combine: (values) => values[0] ?? null });
|
|
903
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
904
|
+
const icon = (severity) => {
|
|
905
|
+
const svg = document.createElementNS(SVG_NS, "svg");
|
|
906
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
907
|
+
svg.setAttribute("width", "14");
|
|
908
|
+
svg.setAttribute("height", "14");
|
|
909
|
+
svg.setAttribute("aria-hidden", "true");
|
|
910
|
+
svg.setAttribute("focusable", "false");
|
|
911
|
+
svg.setAttribute("class", "cm-finding-icon");
|
|
912
|
+
const shape = document.createElementNS(SVG_NS, "path");
|
|
913
|
+
shape.setAttribute("fill", "currentColor");
|
|
914
|
+
const glyph = document.createElementNS(SVG_NS, "path");
|
|
915
|
+
glyph.setAttribute("fill", "none");
|
|
916
|
+
glyph.setAttribute("stroke", "var(--h-content-background)");
|
|
917
|
+
glyph.setAttribute("stroke-width", "1.6");
|
|
918
|
+
glyph.setAttribute("stroke-linecap", "round");
|
|
919
|
+
if (severity === "blocking") {
|
|
920
|
+
shape.setAttribute("d", "M5 1h6l4 4v6l-4 4H5l-4-4V5z");
|
|
921
|
+
glyph.setAttribute("d", "M8 4.5v4M8 11v.5");
|
|
922
|
+
} else {
|
|
923
|
+
shape.setAttribute("d", "M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1z");
|
|
924
|
+
glyph.setAttribute("d", "M8 7.2V11.5M8 4.6v.5");
|
|
925
|
+
}
|
|
926
|
+
svg.append(shape, glyph);
|
|
927
|
+
return svg;
|
|
928
|
+
};
|
|
929
|
+
const rangeLabel$1 = (start, end) => start === end ? `line ${start}` : `lines ${start}-${end}`;
|
|
930
|
+
const severityText = (severity) => severity === "blocking" ? "Blocking" : "Note";
|
|
931
|
+
var FindingBox = class extends WidgetType {
|
|
932
|
+
placed;
|
|
933
|
+
actionLabel;
|
|
934
|
+
constructor(placed, actionLabel) {
|
|
935
|
+
super();
|
|
936
|
+
this.placed = placed;
|
|
937
|
+
this.actionLabel = actionLabel;
|
|
938
|
+
}
|
|
939
|
+
eq(other) {
|
|
940
|
+
const a = this.placed.finding;
|
|
941
|
+
const b = other.placed.finding;
|
|
942
|
+
return a.id === b.id && a.severity === b.severity && a.title === b.title && a.detail === b.detail && a.side === b.side && a.startLine === b.startLine && a.endLine === b.endLine && this.placed.end === other.placed.end && this.actionLabel === other.actionLabel;
|
|
943
|
+
}
|
|
944
|
+
toDOM(view) {
|
|
945
|
+
const f = this.placed.finding;
|
|
946
|
+
const box = document.createElement("div");
|
|
947
|
+
box.className = `cm-finding-box cm-finding-${f.severity}`;
|
|
948
|
+
box.setAttribute("role", "group");
|
|
949
|
+
box.setAttribute("aria-label", `${severityText(f.severity)} finding on ${rangeLabel$1(f.startLine, f.endLine)}`);
|
|
950
|
+
const head = document.createElement("div");
|
|
951
|
+
head.className = "cm-finding-head";
|
|
952
|
+
const severity = document.createElement("span");
|
|
953
|
+
severity.className = "cm-finding-severity";
|
|
954
|
+
severity.append(icon(f.severity), document.createTextNode(severityText(f.severity)));
|
|
955
|
+
const title = document.createElement("span");
|
|
956
|
+
title.className = "cm-finding-title";
|
|
957
|
+
title.textContent = f.title;
|
|
958
|
+
const range = document.createElement("span");
|
|
959
|
+
range.className = "cm-finding-range";
|
|
960
|
+
range.textContent = `${f.side === "original" ? "old " : ""}${rangeLabel$1(f.startLine, f.endLine)}`;
|
|
961
|
+
head.append(severity, title, range);
|
|
962
|
+
box.append(head);
|
|
963
|
+
if (f.detail) {
|
|
964
|
+
const detail = document.createElement("div");
|
|
965
|
+
detail.className = "cm-finding-detail";
|
|
966
|
+
detail.textContent = f.detail;
|
|
967
|
+
box.append(detail);
|
|
968
|
+
}
|
|
969
|
+
if (this.actionLabel) {
|
|
970
|
+
const button = document.createElement("button");
|
|
971
|
+
button.type = "button";
|
|
972
|
+
button.className = "cm-finding-action";
|
|
973
|
+
button.textContent = this.actionLabel;
|
|
974
|
+
button.addEventListener("click", () => view.state.facet(handlersFacet$1)?.action(view, f));
|
|
975
|
+
const actions = document.createElement("div");
|
|
976
|
+
actions.className = "cm-finding-actions";
|
|
977
|
+
actions.append(button);
|
|
978
|
+
box.append(actions);
|
|
979
|
+
}
|
|
980
|
+
return box;
|
|
981
|
+
}
|
|
982
|
+
ignoreEvent() {
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
var FindingGutterMarker = class FindingGutterMarker extends GutterMarker {
|
|
987
|
+
severity;
|
|
988
|
+
elementClass;
|
|
989
|
+
constructor(severity) {
|
|
990
|
+
super();
|
|
991
|
+
this.severity = severity;
|
|
992
|
+
this.elementClass = `cm-finding-gutter cm-finding-gutter-${severity}`;
|
|
993
|
+
}
|
|
994
|
+
eq(other) {
|
|
995
|
+
return other instanceof FindingGutterMarker && other.severity === this.severity;
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
const buildDecorations = (doc, findings, actionLabel) => {
|
|
999
|
+
const ranges = [];
|
|
1000
|
+
for (const placed of findings) {
|
|
1001
|
+
const { start, end } = placed;
|
|
1002
|
+
if (start < 1 || end < start || end > doc.lines) continue;
|
|
1003
|
+
if (placed.mark) for (let n = start; n <= end; n++) ranges.push(Decoration.line({ class: `cm-finding-line cm-finding-line-${placed.finding.severity}` }).range(doc.line(n).from));
|
|
1004
|
+
ranges.push(Decoration.widget({
|
|
1005
|
+
widget: new FindingBox(placed, actionLabel),
|
|
1006
|
+
block: true,
|
|
1007
|
+
side: 1
|
|
1008
|
+
}).range(doc.line(end).to));
|
|
1009
|
+
}
|
|
1010
|
+
return Decoration.set(ranges, true);
|
|
1011
|
+
};
|
|
1012
|
+
const buildMarkers = (doc, findings) => {
|
|
1013
|
+
const lines = /* @__PURE__ */ new Map();
|
|
1014
|
+
for (const { finding, start, end, mark } of findings) {
|
|
1015
|
+
if (!mark || start < 1 || end < start || end > doc.lines) continue;
|
|
1016
|
+
for (let n = start; n <= end; n++) if (lines.get(n) !== "blocking") lines.set(n, finding.severity);
|
|
1017
|
+
}
|
|
1018
|
+
const ranges = [...lines].map(([n, severity]) => new FindingGutterMarker(severity).range(doc.line(n).from));
|
|
1019
|
+
return RangeSet.of(ranges, true);
|
|
1020
|
+
};
|
|
1021
|
+
const field$1 = StateField.define({
|
|
1022
|
+
create: () => ({
|
|
1023
|
+
findings: [],
|
|
1024
|
+
actionLabel: "",
|
|
1025
|
+
decorations: Decoration.none
|
|
1026
|
+
}),
|
|
1027
|
+
update(value, tr) {
|
|
1028
|
+
let { findings, actionLabel } = value;
|
|
1029
|
+
let changed = false;
|
|
1030
|
+
for (const effect of tr.effects) if (effect.is(setFindings)) {
|
|
1031
|
+
findings = effect.value.findings;
|
|
1032
|
+
actionLabel = effect.value.actionLabel;
|
|
1033
|
+
changed = true;
|
|
1034
|
+
}
|
|
1035
|
+
if (!changed) return value;
|
|
1036
|
+
return {
|
|
1037
|
+
findings,
|
|
1038
|
+
actionLabel,
|
|
1039
|
+
decorations: buildDecorations(tr.state.doc, findings, actionLabel)
|
|
1040
|
+
};
|
|
1041
|
+
},
|
|
1042
|
+
provide: (f) => [EditorView.decorations.from(f, (v) => v.decorations), lineNumberMarkers.compute([f], (state) => buildMarkers(state.doc, state.field(f).findings))]
|
|
1043
|
+
});
|
|
1044
|
+
function showFindings(view, findings, actionLabel) {
|
|
1045
|
+
view.dispatch({ effects: setFindings.of({
|
|
1046
|
+
findings,
|
|
1047
|
+
actionLabel
|
|
1048
|
+
}) });
|
|
1049
|
+
}
|
|
1050
|
+
function findingExtension(handlers) {
|
|
1051
|
+
return [
|
|
1052
|
+
handlersFacet$1.of(handlers),
|
|
1053
|
+
field$1,
|
|
1054
|
+
EditorView.baseTheme({
|
|
1055
|
+
".cm-finding-gutter-blocking": {
|
|
1056
|
+
boxShadow: "inset 3px 0 0 var(--h-danger-color)",
|
|
1057
|
+
fontWeight: "bold"
|
|
1058
|
+
},
|
|
1059
|
+
".cm-finding-gutter-note": {
|
|
1060
|
+
boxShadow: "inset 3px 0 0 var(--h-info-color, var(--h-primary-color))",
|
|
1061
|
+
fontStyle: "italic"
|
|
1062
|
+
},
|
|
1063
|
+
".cm-finding-line-blocking": { backgroundColor: "var(--h-highlight-background)" },
|
|
1064
|
+
".cm-finding-line-note": { backgroundColor: "var(--h-highlight-background)" },
|
|
1065
|
+
".cm-finding-box": {
|
|
1066
|
+
margin: "4px 8px 4px 48px",
|
|
1067
|
+
padding: "6px 8px",
|
|
1068
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1069
|
+
borderLeft: "3px solid var(--h-info-color, var(--h-primary-color))",
|
|
1070
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1071
|
+
backgroundColor: "var(--h-content-background)",
|
|
1072
|
+
color: "var(--h-text-color)",
|
|
1073
|
+
fontFamily: "inherit"
|
|
1074
|
+
},
|
|
1075
|
+
".cm-finding-box.cm-finding-blocking": { borderLeft: "3px solid var(--h-danger-color)" },
|
|
1076
|
+
".cm-finding-head": {
|
|
1077
|
+
display: "flex",
|
|
1078
|
+
flexWrap: "wrap",
|
|
1079
|
+
gap: "8px",
|
|
1080
|
+
alignItems: "center"
|
|
1081
|
+
},
|
|
1082
|
+
".cm-finding-severity": {
|
|
1083
|
+
display: "inline-flex",
|
|
1084
|
+
alignItems: "center",
|
|
1085
|
+
gap: "4px",
|
|
1086
|
+
fontWeight: "bold"
|
|
1087
|
+
},
|
|
1088
|
+
".cm-finding-blocking .cm-finding-icon": { color: "var(--h-danger-color)" },
|
|
1089
|
+
".cm-finding-note .cm-finding-icon": { color: "var(--h-info-color, var(--h-primary-color))" },
|
|
1090
|
+
".cm-finding-title": { fontWeight: "600" },
|
|
1091
|
+
".cm-finding-range": {
|
|
1092
|
+
color: "var(--h-text-muted-color)",
|
|
1093
|
+
fontSize: "0.75em",
|
|
1094
|
+
marginLeft: "auto"
|
|
1095
|
+
},
|
|
1096
|
+
".cm-finding-detail": {
|
|
1097
|
+
whiteSpace: "pre-wrap",
|
|
1098
|
+
marginTop: "4px"
|
|
1099
|
+
},
|
|
1100
|
+
".cm-finding-actions": { marginTop: "6px" },
|
|
1101
|
+
".cm-finding-action": {
|
|
1102
|
+
font: "inherit",
|
|
1103
|
+
color: "inherit",
|
|
1104
|
+
background: "transparent",
|
|
1105
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1106
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1107
|
+
padding: "2px 10px",
|
|
1108
|
+
cursor: "pointer"
|
|
1109
|
+
},
|
|
1110
|
+
".cm-finding-action:focus-visible": {
|
|
1111
|
+
outline: "2px solid var(--h-primary-color)",
|
|
1112
|
+
outlineOffset: "1px"
|
|
1113
|
+
}
|
|
1114
|
+
})
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
const setThreads = StateEffect.define();
|
|
1118
|
+
const toggleOpen = StateEffect.define();
|
|
1119
|
+
const handlersFacet = Facet.define({ combine: (values) => values[0] ?? null });
|
|
1120
|
+
const rangeLabel = (start, end) => start === end ? `line ${start}` : `lines ${start}-${end}`;
|
|
1121
|
+
const UNITS = [
|
|
1122
|
+
["year", 31536e3],
|
|
1123
|
+
["month", 2592e3],
|
|
1124
|
+
["week", 604800],
|
|
1125
|
+
["day", 86400],
|
|
1126
|
+
["hour", 3600],
|
|
1127
|
+
["minute", 60]
|
|
1128
|
+
];
|
|
1129
|
+
function relativeTime(time, now = Date.now()) {
|
|
1130
|
+
const date = new Date(time).getTime();
|
|
1131
|
+
if (Number.isNaN(date)) return "";
|
|
1132
|
+
const seconds = Math.round((date - now) / 1e3);
|
|
1133
|
+
const format = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
|
|
1134
|
+
for (const [unit, size] of UNITS) if (Math.abs(seconds) >= size) return format.format(Math.round(seconds / size), unit);
|
|
1135
|
+
return format.format(seconds, "second");
|
|
1136
|
+
}
|
|
1137
|
+
const fullTime = (time) => {
|
|
1138
|
+
const date = new Date(time);
|
|
1139
|
+
return Number.isNaN(date.getTime()) ? time : date.toLocaleString();
|
|
1140
|
+
};
|
|
1141
|
+
const sameComments = (a, b) => a.comments.length === b.comments.length && a.comments.every((c, i) => {
|
|
1142
|
+
const o = b.comments[i];
|
|
1143
|
+
return c.id === o.id && c.author === o.author && c.time === o.time && c.text === o.text;
|
|
1144
|
+
});
|
|
1145
|
+
var ThreadBox = class extends WidgetType {
|
|
1146
|
+
placed;
|
|
1147
|
+
open;
|
|
1148
|
+
render;
|
|
1149
|
+
constructor(placed, open, render) {
|
|
1150
|
+
super();
|
|
1151
|
+
this.placed = placed;
|
|
1152
|
+
this.open = open;
|
|
1153
|
+
this.render = render;
|
|
1154
|
+
}
|
|
1155
|
+
eq(other) {
|
|
1156
|
+
const t = this.placed.thread;
|
|
1157
|
+
const o = other.placed.thread;
|
|
1158
|
+
return t.id === o.id && t.resolved === o.resolved && t.side === o.side && t.startLine === o.startLine && t.endLine === o.endLine && sameComments(t, o) && this.placed.end === other.placed.end && this.open === other.open && this.render === other.render;
|
|
1159
|
+
}
|
|
1160
|
+
toDOM(view) {
|
|
1161
|
+
const t = this.placed.thread;
|
|
1162
|
+
const collapsed = t.resolved && !this.open;
|
|
1163
|
+
const box = document.createElement("div");
|
|
1164
|
+
box.className = `cm-thread-box${t.resolved ? " cm-thread-resolved" : ""}${collapsed ? " cm-thread-collapsed" : ""}`;
|
|
1165
|
+
box.setAttribute("role", "group");
|
|
1166
|
+
box.setAttribute("aria-label", `Thread on ${rangeLabel(t.startLine, t.endLine)}`);
|
|
1167
|
+
const first = t.comments[0];
|
|
1168
|
+
const count = t.comments.length;
|
|
1169
|
+
const head = document.createElement("div");
|
|
1170
|
+
head.className = "cm-thread-head";
|
|
1171
|
+
if (t.resolved) {
|
|
1172
|
+
const toggle = document.createElement("button");
|
|
1173
|
+
toggle.type = "button";
|
|
1174
|
+
toggle.className = "cm-thread-toggle";
|
|
1175
|
+
toggle.setAttribute("aria-expanded", String(!collapsed));
|
|
1176
|
+
toggle.textContent = collapsed ? `Resolved · ${first?.author ?? ""} · ${count} comment${count === 1 ? "" : "s"}` : "Resolved";
|
|
1177
|
+
toggle.addEventListener("click", () => view.dispatch({ effects: toggleOpen.of(t.id) }));
|
|
1178
|
+
head.append(toggle);
|
|
1179
|
+
}
|
|
1180
|
+
const range = document.createElement("span");
|
|
1181
|
+
range.className = "cm-thread-range";
|
|
1182
|
+
range.textContent = `${t.side === "original" ? "old " : ""}${rangeLabel(t.startLine, t.endLine)}`;
|
|
1183
|
+
head.append(range);
|
|
1184
|
+
const resolve = document.createElement("button");
|
|
1185
|
+
resolve.type = "button";
|
|
1186
|
+
resolve.className = "cm-thread-resolve";
|
|
1187
|
+
resolve.textContent = t.resolved ? "Unresolve" : "Resolve";
|
|
1188
|
+
resolve.addEventListener("click", () => view.state.facet(handlersFacet)?.resolve(view, t.id, !t.resolved));
|
|
1189
|
+
head.append(resolve);
|
|
1190
|
+
box.append(head);
|
|
1191
|
+
if (collapsed) return box;
|
|
1192
|
+
for (const c of t.comments) {
|
|
1193
|
+
const item = document.createElement("div");
|
|
1194
|
+
item.className = "cm-thread-comment";
|
|
1195
|
+
const meta = document.createElement("div");
|
|
1196
|
+
meta.className = "cm-thread-meta";
|
|
1197
|
+
const author = document.createElement("span");
|
|
1198
|
+
author.className = "cm-thread-author";
|
|
1199
|
+
author.textContent = c.author;
|
|
1200
|
+
const time = document.createElement("time");
|
|
1201
|
+
time.className = "cm-thread-time";
|
|
1202
|
+
time.dateTime = c.time;
|
|
1203
|
+
time.title = fullTime(c.time);
|
|
1204
|
+
time.textContent = relativeTime(c.time);
|
|
1205
|
+
meta.append(author, time);
|
|
1206
|
+
const body = document.createElement("div");
|
|
1207
|
+
body.className = "cm-thread-text";
|
|
1208
|
+
if (this.render) body.innerHTML = this.render(c.text);
|
|
1209
|
+
else body.textContent = c.text;
|
|
1210
|
+
item.append(meta, body);
|
|
1211
|
+
box.append(item);
|
|
1212
|
+
}
|
|
1213
|
+
const input = document.createElement("textarea");
|
|
1214
|
+
input.className = "cm-thread-input";
|
|
1215
|
+
input.rows = 2;
|
|
1216
|
+
input.placeholder = "Reply";
|
|
1217
|
+
input.setAttribute("aria-label", `Reply to thread on ${rangeLabel(t.startLine, t.endLine)}`);
|
|
1218
|
+
const send = document.createElement("button");
|
|
1219
|
+
send.type = "button";
|
|
1220
|
+
send.className = "cm-thread-reply";
|
|
1221
|
+
send.textContent = "Reply";
|
|
1222
|
+
send.disabled = true;
|
|
1223
|
+
const submit = () => {
|
|
1224
|
+
const text = input.value.trim();
|
|
1225
|
+
if (!text) return;
|
|
1226
|
+
input.value = "";
|
|
1227
|
+
send.disabled = true;
|
|
1228
|
+
view.state.facet(handlersFacet)?.reply(view, t.id, text);
|
|
1229
|
+
};
|
|
1230
|
+
input.addEventListener("input", () => {
|
|
1231
|
+
send.disabled = !input.value.trim();
|
|
1232
|
+
});
|
|
1233
|
+
input.addEventListener("keydown", (event) => {
|
|
1234
|
+
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
|
|
1235
|
+
submit();
|
|
1236
|
+
event.preventDefault();
|
|
1237
|
+
}
|
|
1238
|
+
event.stopPropagation();
|
|
1239
|
+
});
|
|
1240
|
+
send.addEventListener("click", submit);
|
|
1241
|
+
const actions = document.createElement("div");
|
|
1242
|
+
actions.className = "cm-thread-actions";
|
|
1243
|
+
actions.append(send);
|
|
1244
|
+
box.append(input, actions);
|
|
1245
|
+
return box;
|
|
1246
|
+
}
|
|
1247
|
+
ignoreEvent() {
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
const decorate$1 = (doc, threads, open, render) => {
|
|
1252
|
+
const ranges = [];
|
|
1253
|
+
for (const placed of threads) {
|
|
1254
|
+
const { start, end } = placed;
|
|
1255
|
+
if (start < 1 || end < start || end > doc.lines) continue;
|
|
1256
|
+
if (placed.mark) for (let n = start; n <= end; n++) ranges.push(Decoration.line({ class: "cm-thread-line" }).range(doc.line(n).from));
|
|
1257
|
+
ranges.push(Decoration.widget({
|
|
1258
|
+
widget: new ThreadBox(placed, open.has(placed.thread.id), render),
|
|
1259
|
+
block: true,
|
|
1260
|
+
side: 2
|
|
1261
|
+
}).range(doc.line(end).to));
|
|
1262
|
+
}
|
|
1263
|
+
return Decoration.set(ranges, true);
|
|
1264
|
+
};
|
|
1265
|
+
const field = StateField.define({
|
|
1266
|
+
create: () => ({
|
|
1267
|
+
threads: [],
|
|
1268
|
+
render: null,
|
|
1269
|
+
open: /* @__PURE__ */ new Set(),
|
|
1270
|
+
decorations: Decoration.none
|
|
1271
|
+
}),
|
|
1272
|
+
update(value, tr) {
|
|
1273
|
+
let { threads, render, open } = value;
|
|
1274
|
+
let changed = false;
|
|
1275
|
+
for (const effect of tr.effects) if (effect.is(setThreads)) {
|
|
1276
|
+
threads = effect.value.threads;
|
|
1277
|
+
render = effect.value.render;
|
|
1278
|
+
changed = true;
|
|
1279
|
+
} else if (effect.is(toggleOpen)) {
|
|
1280
|
+
const next = new Set(open);
|
|
1281
|
+
if (!next.delete(effect.value)) next.add(effect.value);
|
|
1282
|
+
open = next;
|
|
1283
|
+
changed = true;
|
|
1284
|
+
}
|
|
1285
|
+
if (!changed) return value;
|
|
1286
|
+
return {
|
|
1287
|
+
threads,
|
|
1288
|
+
render,
|
|
1289
|
+
open,
|
|
1290
|
+
decorations: decorate$1(tr.state.doc, threads, open, render)
|
|
1291
|
+
};
|
|
1292
|
+
},
|
|
1293
|
+
provide: (f) => EditorView.decorations.from(f, (v) => v.decorations)
|
|
1294
|
+
});
|
|
1295
|
+
function showThreads(view, threads, render) {
|
|
1296
|
+
view.dispatch({ effects: setThreads.of({
|
|
1297
|
+
threads,
|
|
1298
|
+
render
|
|
1299
|
+
}) });
|
|
1300
|
+
}
|
|
1301
|
+
function threadExtension(handlers) {
|
|
1302
|
+
return [
|
|
1303
|
+
handlersFacet.of(handlers),
|
|
1304
|
+
field,
|
|
1305
|
+
EditorView.baseTheme({
|
|
1306
|
+
".cm-thread-line": { backgroundColor: "var(--h-highlight-background)" },
|
|
1307
|
+
".cm-thread-box": {
|
|
1308
|
+
margin: "4px 8px 4px 48px",
|
|
1309
|
+
padding: "6px 8px",
|
|
1310
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1311
|
+
borderLeft: "3px solid var(--h-primary-color)",
|
|
1312
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1313
|
+
backgroundColor: "var(--h-content-background)",
|
|
1314
|
+
color: "var(--h-text-color)",
|
|
1315
|
+
fontFamily: "inherit"
|
|
1316
|
+
},
|
|
1317
|
+
".cm-thread-resolved": { borderLeftColor: "var(--h-content-border-color)" },
|
|
1318
|
+
".cm-thread-head": {
|
|
1319
|
+
display: "flex",
|
|
1320
|
+
gap: "8px",
|
|
1321
|
+
alignItems: "center"
|
|
1322
|
+
},
|
|
1323
|
+
".cm-thread-range": {
|
|
1324
|
+
color: "var(--h-text-muted-color)",
|
|
1325
|
+
fontSize: "0.75em",
|
|
1326
|
+
marginLeft: "auto"
|
|
1327
|
+
},
|
|
1328
|
+
".cm-thread-comment": {
|
|
1329
|
+
marginTop: "6px",
|
|
1330
|
+
paddingTop: "6px",
|
|
1331
|
+
borderTop: "1px solid var(--h-content-border-color)"
|
|
1332
|
+
},
|
|
1333
|
+
".cm-thread-comment:first-of-type": {
|
|
1334
|
+
borderTop: "none",
|
|
1335
|
+
paddingTop: "0"
|
|
1336
|
+
},
|
|
1337
|
+
".cm-thread-meta": {
|
|
1338
|
+
display: "flex",
|
|
1339
|
+
gap: "8px",
|
|
1340
|
+
fontSize: "0.75em"
|
|
1341
|
+
},
|
|
1342
|
+
".cm-thread-author": { fontWeight: "600" },
|
|
1343
|
+
".cm-thread-time": { color: "var(--h-text-muted-color)" },
|
|
1344
|
+
".cm-thread-text": { whiteSpace: "pre-wrap" },
|
|
1345
|
+
".cm-thread-input": {
|
|
1346
|
+
display: "block",
|
|
1347
|
+
width: "100%",
|
|
1348
|
+
boxSizing: "border-box",
|
|
1349
|
+
marginTop: "8px",
|
|
1350
|
+
font: "inherit",
|
|
1351
|
+
color: "inherit",
|
|
1352
|
+
background: "transparent",
|
|
1353
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1354
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1355
|
+
resize: "vertical"
|
|
1356
|
+
},
|
|
1357
|
+
".cm-thread-actions": {
|
|
1358
|
+
display: "flex",
|
|
1359
|
+
gap: "6px",
|
|
1360
|
+
marginTop: "6px"
|
|
1361
|
+
},
|
|
1362
|
+
".cm-thread-box button": {
|
|
1363
|
+
font: "inherit",
|
|
1364
|
+
color: "inherit",
|
|
1365
|
+
background: "transparent",
|
|
1366
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1367
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1368
|
+
padding: "2px 10px",
|
|
1369
|
+
cursor: "pointer"
|
|
1370
|
+
},
|
|
1371
|
+
".cm-thread-box button.cm-thread-toggle": {
|
|
1372
|
+
border: "none",
|
|
1373
|
+
padding: "0",
|
|
1374
|
+
textAlign: "left"
|
|
1375
|
+
},
|
|
1376
|
+
".cm-thread-box button:disabled": {
|
|
1377
|
+
opacity: "0.6",
|
|
1378
|
+
cursor: "default"
|
|
1379
|
+
},
|
|
1380
|
+
".cm-thread-box button:focus-visible, .cm-thread-input:focus-visible": {
|
|
1381
|
+
outline: "2px solid var(--h-primary-color)",
|
|
1382
|
+
outlineOffset: "1px"
|
|
1383
|
+
}
|
|
1384
|
+
})
|
|
1385
|
+
];
|
|
1386
|
+
}
|
|
1387
|
+
const HX_DIFF_PALETTE = {
|
|
1388
|
+
added: {
|
|
1389
|
+
background: {
|
|
1390
|
+
light: "rgba(22, 163, 74, 0.12)",
|
|
1391
|
+
dark: "rgba(74, 222, 128, 0.14)"
|
|
1392
|
+
},
|
|
1393
|
+
mark: {
|
|
1394
|
+
light: "rgba(22, 163, 74, 0.32)",
|
|
1395
|
+
dark: "rgba(74, 222, 128, 0.34)"
|
|
1396
|
+
},
|
|
1397
|
+
sign: {
|
|
1398
|
+
light: "#15803d",
|
|
1399
|
+
dark: "#86efac"
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
removed: {
|
|
1403
|
+
background: {
|
|
1404
|
+
light: "rgba(220, 38, 38, 0.1)",
|
|
1405
|
+
dark: "rgba(248, 113, 113, 0.14)"
|
|
1406
|
+
},
|
|
1407
|
+
mark: {
|
|
1408
|
+
light: "rgba(220, 38, 38, 0.3)",
|
|
1409
|
+
dark: "rgba(248, 113, 113, 0.34)"
|
|
1410
|
+
},
|
|
1411
|
+
sign: {
|
|
1412
|
+
light: "#b91c1c",
|
|
1413
|
+
dark: "#fca5a5"
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
const KINDS = Object.keys(HX_DIFF_PALETTE);
|
|
1418
|
+
const PARTS = [
|
|
1419
|
+
"background",
|
|
1420
|
+
"mark",
|
|
1421
|
+
"sign"
|
|
1422
|
+
];
|
|
1423
|
+
const color = (kind, part) => `var(--hx-diff-${kind}-${part}, var(--hx-diff-default-${kind}-${part}))`;
|
|
1424
|
+
const defaults = (mode) => Object.fromEntries(KINDS.flatMap((k) => PARTS.map((p) => [`--hx-diff-default-${k}-${p}`, HX_DIFF_PALETTE[k][p][mode]])));
|
|
1425
|
+
const ADDED_LINE = "&.cm-merge-b .cm-changedLine, & .cm-inlineChangedLine";
|
|
1426
|
+
const REMOVED_LINE = "&.cm-merge-a .cm-changedLine, & .cm-deletedChunk";
|
|
1427
|
+
const ADDED_MARK = "&.cm-merge-b .cm-changedText, & .cm-inlineChangedLine .cm-changedText";
|
|
1428
|
+
const REMOVED_MARK = "&.cm-merge-a .cm-changedText, & .cm-deletedChunk .cm-deletedText";
|
|
1429
|
+
const ADDED_SIGN = "&.cm-merge-b .cm-changedLineGutter, & .cm-inlineChangedLineGutter";
|
|
1430
|
+
const REMOVED_SIGN = "&.cm-merge-a .cm-changedLineGutter, & .cm-deletedLineGutter";
|
|
1431
|
+
const sign = (kind, char) => ({
|
|
1432
|
+
color: color(kind, "sign"),
|
|
1433
|
+
background: "transparent",
|
|
1434
|
+
textAlign: "center",
|
|
1435
|
+
fontWeight: "600",
|
|
1436
|
+
"&::before": { content: `"${char}"` }
|
|
1437
|
+
});
|
|
1438
|
+
function hxDiffTheme() {
|
|
1439
|
+
return [EditorView.baseTheme({
|
|
1440
|
+
"&": defaults("light"),
|
|
1441
|
+
".app-dark &": defaults("dark")
|
|
1442
|
+
}), EditorView.theme({
|
|
1443
|
+
[ADDED_LINE]: { backgroundColor: color("added", "background") },
|
|
1444
|
+
[REMOVED_LINE]: { backgroundColor: color("removed", "background") },
|
|
1445
|
+
[ADDED_MARK]: { background: color("added", "mark") },
|
|
1446
|
+
[REMOVED_MARK]: { background: color("removed", "mark") },
|
|
1447
|
+
".cm-changeGutter": {
|
|
1448
|
+
width: "1.25rem",
|
|
1449
|
+
padding: "0"
|
|
1450
|
+
},
|
|
1451
|
+
[ADDED_SIGN]: sign("added", "+"),
|
|
1452
|
+
[REMOVED_SIGN]: sign("removed", "-"),
|
|
1453
|
+
".cm-collapsedLines": {
|
|
1454
|
+
color: "var(--h-text-muted-color)",
|
|
1455
|
+
background: "var(--h-content-hover-background)"
|
|
1456
|
+
},
|
|
1457
|
+
".cm-deletedChunk": { backgroundColor: color("removed", "background") },
|
|
1458
|
+
".cm-chunkButtons": {
|
|
1459
|
+
display: "flex",
|
|
1460
|
+
gap: "6px",
|
|
1461
|
+
padding: "2px 4px"
|
|
1462
|
+
},
|
|
1463
|
+
".cm-review-button": {
|
|
1464
|
+
font: "inherit",
|
|
1465
|
+
color: "inherit",
|
|
1466
|
+
background: "var(--h-content-background)",
|
|
1467
|
+
border: "1px solid var(--h-content-border-color)",
|
|
1468
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
1469
|
+
padding: "0 8px",
|
|
1470
|
+
cursor: "pointer"
|
|
1471
|
+
},
|
|
1472
|
+
".cm-review-button:hover": { background: "var(--h-content-hover-background)" },
|
|
1473
|
+
".cm-review-button:focus-visible": {
|
|
1474
|
+
outline: "2px solid var(--h-primary-color)",
|
|
1475
|
+
outlineOffset: "1px"
|
|
1476
|
+
}
|
|
1477
|
+
})];
|
|
1478
|
+
}
|
|
1479
|
+
const DEFAULT_SPLIT_MIN_WIDTH = 900;
|
|
1480
|
+
const DEFAULT_COLLAPSE = {
|
|
1481
|
+
margin: 3,
|
|
1482
|
+
minSize: 4
|
|
1483
|
+
};
|
|
1484
|
+
var HxDiffView = class HxDiffView {
|
|
1485
|
+
#languages = inject(HX_CODE_LANGUAGES);
|
|
1486
|
+
#sanitizer = inject(DomSanitizer);
|
|
1487
|
+
original = input.required(...ngDevMode ? [{ debugName: "original" }] : /* istanbul ignore next */ []);
|
|
1488
|
+
modified = input.required(...ngDevMode ? [{ debugName: "modified" }] : /* istanbul ignore next */ []);
|
|
1489
|
+
path = input("", ...ngDevMode ? [{ debugName: "path" }] : /* istanbul ignore next */ []);
|
|
1490
|
+
layout = input("split", ...ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []);
|
|
1491
|
+
splitMinWidth = input(DEFAULT_SPLIT_MIN_WIDTH, ...ngDevMode ? [{ debugName: "splitMinWidth" }] : /* istanbul ignore next */ []);
|
|
1492
|
+
collapseUnchanged = input(true, ...ngDevMode ? [{ debugName: "collapseUnchanged" }] : /* istanbul ignore next */ []);
|
|
1493
|
+
comments = input([], ...ngDevMode ? [{ debugName: "comments" }] : /* istanbul ignore next */ []);
|
|
1494
|
+
commentable = input(false, ...ngDevMode ? [{ debugName: "commentable" }] : /* istanbul ignore next */ []);
|
|
1495
|
+
findings = input([], ...ngDevMode ? [{ debugName: "findings" }] : /* istanbul ignore next */ []);
|
|
1496
|
+
findingActionLabel = input("", ...ngDevMode ? [{ debugName: "findingActionLabel" }] : /* istanbul ignore next */ []);
|
|
1497
|
+
findingAction = output();
|
|
1498
|
+
threads = input([], ...ngDevMode ? [{ debugName: "threads" }] : /* istanbul ignore next */ []);
|
|
1499
|
+
renderComment = input(null, ...ngDevMode ? [{ debugName: "renderComment" }] : /* istanbul ignore next */ []);
|
|
1500
|
+
replyAdded = output();
|
|
1501
|
+
resolvedChange = output();
|
|
1502
|
+
commentAdded = output();
|
|
1503
|
+
reviewable = input(false, ...ngDevMode ? [{ debugName: "reviewable" }] : /* istanbul ignore next */ []);
|
|
1504
|
+
changeDecided = output();
|
|
1505
|
+
ariaLabel = input(null, {
|
|
1506
|
+
...ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {},
|
|
1507
|
+
alias: "aria-label"
|
|
1508
|
+
});
|
|
1509
|
+
ariaLabelledby = input(null, {
|
|
1510
|
+
...ngDevMode ? { debugName: "ariaLabelledby" } : /* istanbul ignore next */ {},
|
|
1511
|
+
alias: "aria-labelledby"
|
|
1512
|
+
});
|
|
1513
|
+
#host = inject(ElementRef);
|
|
1514
|
+
#width = signal(null, ...ngDevMode ? [{ debugName: "#width" }] : /* istanbul ignore next */ []);
|
|
1515
|
+
#changes = signal(0, ...ngDevMode ? [{ debugName: "#changes" }] : /* istanbul ignore next */ []);
|
|
1516
|
+
#current = signal(0, ...ngDevMode ? [{ debugName: "#current" }] : /* istanbul ignore next */ []);
|
|
1517
|
+
changeCount = this.#changes.asReadonly();
|
|
1518
|
+
currentChange = this.#current.asReadonly();
|
|
1519
|
+
#result = signal("", ...ngDevMode ? [{ debugName: "#result" }] : /* istanbul ignore next */ []);
|
|
1520
|
+
result = this.#result.asReadonly();
|
|
1521
|
+
pendingChanges = this.#changes.asReadonly();
|
|
1522
|
+
effectiveLayout = computed(() => {
|
|
1523
|
+
const layout = this.layout();
|
|
1524
|
+
if (layout !== "auto") return layout;
|
|
1525
|
+
const width = this.#width();
|
|
1526
|
+
if (width === null) return null;
|
|
1527
|
+
return width >= this.splitMinWidth() ? "split" : "unified";
|
|
1528
|
+
}, ...ngDevMode ? [{ debugName: "effectiveLayout" }] : /* istanbul ignore next */ []);
|
|
1529
|
+
container = viewChild.required("container", ...ngDevMode ? [{ debugName: "container" }] : /* istanbul ignore next */ []);
|
|
1530
|
+
#ready = signal(false, ...ngDevMode ? [{ debugName: "#ready" }] : /* istanbul ignore next */ []);
|
|
1531
|
+
#language = new Compartment();
|
|
1532
|
+
#review = new Compartment();
|
|
1533
|
+
#built = signal(0, ...ngDevMode ? [{ debugName: "#built" }] : /* istanbul ignore next */ []);
|
|
1534
|
+
#reviewOn = false;
|
|
1535
|
+
#commentExtension = commentExtension({
|
|
1536
|
+
opened: (view) => {
|
|
1537
|
+
const views = this.#views;
|
|
1538
|
+
if (!views || views.original === views.modified) return;
|
|
1539
|
+
discardDraft(view === views.original ? views.modified : views.original);
|
|
1540
|
+
},
|
|
1541
|
+
saved: (view, startLine, endLine, text) => {
|
|
1542
|
+
const views = this.#views;
|
|
1543
|
+
const side = views && views.original !== views.modified && view === views.original ? "original" : "modified";
|
|
1544
|
+
this.commentAdded.emit({
|
|
1545
|
+
side,
|
|
1546
|
+
startLine,
|
|
1547
|
+
endLine,
|
|
1548
|
+
text,
|
|
1549
|
+
quote: quoteOf(view, startLine, endLine)
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
#findingExtension = findingExtension({ action: (view, finding) => {
|
|
1554
|
+
const views = this.#views;
|
|
1555
|
+
const split = !!views && views.original !== views.modified;
|
|
1556
|
+
let quote = "";
|
|
1557
|
+
if (views && finding.endLine >= finding.startLine && finding.startLine >= 1) {
|
|
1558
|
+
const target = split ? finding.side === "original" ? views.original : views.modified : view;
|
|
1559
|
+
const doc = !split && finding.side === "original" ? getOriginalDoc(target.state) : target.state.doc;
|
|
1560
|
+
if (finding.endLine <= doc.lines) quote = doc.sliceString(doc.line(finding.startLine).from, doc.line(finding.endLine).to);
|
|
1561
|
+
}
|
|
1562
|
+
this.findingAction.emit({
|
|
1563
|
+
id: finding.id,
|
|
1564
|
+
quote
|
|
1565
|
+
});
|
|
1566
|
+
} });
|
|
1567
|
+
#threadExtension = threadExtension({
|
|
1568
|
+
reply: (_view, threadId, text) => this.replyAdded.emit({
|
|
1569
|
+
threadId,
|
|
1570
|
+
text
|
|
1571
|
+
}),
|
|
1572
|
+
resolve: (_view, threadId, resolved) => this.resolvedChange.emit({
|
|
1573
|
+
threadId,
|
|
1574
|
+
resolved
|
|
1575
|
+
})
|
|
1576
|
+
});
|
|
1577
|
+
#renderCache = null;
|
|
1578
|
+
#generation = 0;
|
|
1579
|
+
#destroy = null;
|
|
1580
|
+
#undecided = [];
|
|
1581
|
+
#views = null;
|
|
1582
|
+
#reviewMode = false;
|
|
1583
|
+
constructor() {
|
|
1584
|
+
const destroyRef = inject(DestroyRef);
|
|
1585
|
+
let observer = null;
|
|
1586
|
+
afterNextRender(() => {
|
|
1587
|
+
this.#ready.set(true);
|
|
1588
|
+
if (typeof ResizeObserver === "undefined") {
|
|
1589
|
+
this.#width.set(this.#host.nativeElement.getBoundingClientRect().width);
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
observer = new ResizeObserver((entries) => {
|
|
1593
|
+
const entry = entries[entries.length - 1];
|
|
1594
|
+
if (entry) this.#width.set(entry.contentRect.width);
|
|
1595
|
+
});
|
|
1596
|
+
observer.observe(this.#host.nativeElement);
|
|
1597
|
+
});
|
|
1598
|
+
destroyRef.onDestroy(() => {
|
|
1599
|
+
observer?.disconnect();
|
|
1600
|
+
this.#generation++;
|
|
1601
|
+
this.#teardown();
|
|
1602
|
+
});
|
|
1603
|
+
effect(() => {
|
|
1604
|
+
this.#built();
|
|
1605
|
+
this.commentable();
|
|
1606
|
+
this.comments();
|
|
1607
|
+
this.findings();
|
|
1608
|
+
this.findingActionLabel();
|
|
1609
|
+
this.threads();
|
|
1610
|
+
this.renderComment();
|
|
1611
|
+
untracked(() => this.#showReview());
|
|
1612
|
+
});
|
|
1613
|
+
effect(() => {
|
|
1614
|
+
if (!this.#ready()) return;
|
|
1615
|
+
const original = this.original();
|
|
1616
|
+
const modified = this.modified();
|
|
1617
|
+
const layout = this.effectiveLayout();
|
|
1618
|
+
if (layout === null) return;
|
|
1619
|
+
const reviewable = this.reviewable() && layout === "unified";
|
|
1620
|
+
const path = this.path();
|
|
1621
|
+
const collapse = this.#collapse();
|
|
1622
|
+
const label = this.#labels();
|
|
1623
|
+
const generation = ++this.#generation;
|
|
1624
|
+
untracked(() => {
|
|
1625
|
+
this.#teardown();
|
|
1626
|
+
const views = this.#build(layout, original, modified, collapse, label, reviewable);
|
|
1627
|
+
const count = this.#chunks(views[views.length - 1]).length;
|
|
1628
|
+
this.#undecided = Array.from({ length: count }, (_, i) => i);
|
|
1629
|
+
this.#changes.set(count);
|
|
1630
|
+
this.#result.set(modified);
|
|
1631
|
+
this.#built.update((n) => n + 1);
|
|
1632
|
+
hxLoadLanguage(path, this.#languages).then((support) => {
|
|
1633
|
+
if (generation !== this.#generation || !support) return;
|
|
1634
|
+
for (const view of views) view.dispatch({ effects: this.#language.reconfigure(support) });
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
#showReview() {
|
|
1640
|
+
const views = this.#views;
|
|
1641
|
+
if (!views) return;
|
|
1642
|
+
const commentable = this.commentable();
|
|
1643
|
+
const comments = this.comments();
|
|
1644
|
+
const findings = this.findings();
|
|
1645
|
+
const actionLabel = this.findingActionLabel();
|
|
1646
|
+
const threads = this.threads();
|
|
1647
|
+
const render = this.#renderer();
|
|
1648
|
+
const split = views.original !== views.modified;
|
|
1649
|
+
for (const [side, view] of [["original", views.original], ["modified", views.modified]]) {
|
|
1650
|
+
if (!split && side === "original") continue;
|
|
1651
|
+
if (this.#reviewOn !== commentable) view.dispatch({ effects: this.#review.reconfigure(commentable ? this.#commentExtension : []) });
|
|
1652
|
+
showComments(view, commentable ? comments.flatMap((c) => this.#place(c, side, view, views.modified, split)) : []);
|
|
1653
|
+
showFindings(view, findings.flatMap((f) => this.#placeFinding(f, side, view, views.modified, split)), actionLabel);
|
|
1654
|
+
showThreads(view, threads.flatMap((t) => this.#placeThread(t, side, view, views.modified, split)), render);
|
|
1655
|
+
}
|
|
1656
|
+
this.#reviewOn = commentable;
|
|
1657
|
+
}
|
|
1658
|
+
#place(c, side, view, modified, split) {
|
|
1659
|
+
const at = this.#placeLines(c, side, view, modified, split);
|
|
1660
|
+
return at ? [{
|
|
1661
|
+
comment: c,
|
|
1662
|
+
...at
|
|
1663
|
+
}] : [];
|
|
1664
|
+
}
|
|
1665
|
+
#placeFinding(f, side, view, modified, split) {
|
|
1666
|
+
const at = this.#placeLines(f, side, view, modified, split);
|
|
1667
|
+
return at ? [{
|
|
1668
|
+
finding: f,
|
|
1669
|
+
...at
|
|
1670
|
+
}] : [];
|
|
1671
|
+
}
|
|
1672
|
+
#placeThread(t, side, view, modified, split) {
|
|
1673
|
+
const at = this.#placeLines(t, side, view, modified, split);
|
|
1674
|
+
return at ? [{
|
|
1675
|
+
thread: t,
|
|
1676
|
+
...at
|
|
1677
|
+
}] : [];
|
|
1678
|
+
}
|
|
1679
|
+
#renderer() {
|
|
1680
|
+
const render = this.renderComment();
|
|
1681
|
+
if (!render) return null;
|
|
1682
|
+
const cached = this.#renderCache;
|
|
1683
|
+
if (cached?.source === render) return cached.wrapped;
|
|
1684
|
+
const wrapped = (text) => this.#sanitizer.sanitize(SecurityContext.HTML, render(text)) ?? "";
|
|
1685
|
+
this.#renderCache = {
|
|
1686
|
+
source: render,
|
|
1687
|
+
wrapped
|
|
1688
|
+
};
|
|
1689
|
+
return wrapped;
|
|
1690
|
+
}
|
|
1691
|
+
#placeLines(c, side, view, modified, split) {
|
|
1692
|
+
if (split ? c.side !== side : false) return null;
|
|
1693
|
+
const lines = view.state.doc.lines;
|
|
1694
|
+
if (c.side === "modified" || split) {
|
|
1695
|
+
if (c.endLine < c.startLine || c.startLine < 1 || c.endLine > lines) return null;
|
|
1696
|
+
return {
|
|
1697
|
+
start: c.startLine,
|
|
1698
|
+
end: c.endLine,
|
|
1699
|
+
mark: true
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
const original = getOriginalDoc(modified.state);
|
|
1703
|
+
if (c.endLine < c.startLine || c.startLine < 1 || c.endLine > original.lines) return null;
|
|
1704
|
+
const at = this.#map(modified, original.line(c.endLine).from, true);
|
|
1705
|
+
const end = modified.state.doc.lineAt(Math.min(at, modified.state.doc.length)).number;
|
|
1706
|
+
return {
|
|
1707
|
+
start: end,
|
|
1708
|
+
end,
|
|
1709
|
+
mark: false
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
acceptAll() {
|
|
1713
|
+
this.#decideAll("accept");
|
|
1714
|
+
}
|
|
1715
|
+
rejectAll() {
|
|
1716
|
+
this.#decideAll("reject");
|
|
1717
|
+
}
|
|
1718
|
+
#decideAll(decision) {
|
|
1719
|
+
const view = this.#views?.modified;
|
|
1720
|
+
if (!view || !this.#reviewing) return;
|
|
1721
|
+
for (let chunk = this.#chunks(view)[0]; chunk; chunk = this.#chunks(view)[0]) if (!this.#decide(view, chunk.fromB, decision)) break;
|
|
1722
|
+
}
|
|
1723
|
+
#decide(view, pos, decision) {
|
|
1724
|
+
const position = this.#chunks(view).findIndex((c) => c.fromB <= pos && pos <= c.endB);
|
|
1725
|
+
if (position < 0) return false;
|
|
1726
|
+
if (!(decision === "accept" ? acceptChunk(view, pos) : rejectChunk(view, pos))) return false;
|
|
1727
|
+
const [index] = this.#undecided.splice(position, 1);
|
|
1728
|
+
this.#sync(view);
|
|
1729
|
+
this.changeDecided.emit({
|
|
1730
|
+
index,
|
|
1731
|
+
decision
|
|
1732
|
+
});
|
|
1733
|
+
return true;
|
|
1734
|
+
}
|
|
1735
|
+
#control(type) {
|
|
1736
|
+
const button = document.createElement("button");
|
|
1737
|
+
button.type = "button";
|
|
1738
|
+
button.className = `cm-review-button cm-review-${type}`;
|
|
1739
|
+
button.textContent = type === "accept" ? "Accept" : "Reject";
|
|
1740
|
+
button.setAttribute("aria-label", type === "accept" ? "Accept this change" : "Reject this change");
|
|
1741
|
+
button.addEventListener("click", (e) => {
|
|
1742
|
+
e.preventDefault();
|
|
1743
|
+
const view = this.#views?.modified;
|
|
1744
|
+
const widget = button.closest(".cm-deletedChunk");
|
|
1745
|
+
if (!view || !widget) return;
|
|
1746
|
+
this.#decide(view, view.posAtDOM(widget), type);
|
|
1747
|
+
});
|
|
1748
|
+
return button;
|
|
1749
|
+
}
|
|
1750
|
+
#sync(view) {
|
|
1751
|
+
const count = this.#chunks(view).length;
|
|
1752
|
+
if (count !== this.#changes()) this.#changes.set(count);
|
|
1753
|
+
this.#result.set(view.state.doc.toString());
|
|
1754
|
+
this.#current.set(this.#indexAt(view));
|
|
1755
|
+
}
|
|
1756
|
+
next() {
|
|
1757
|
+
const count = this.#changes();
|
|
1758
|
+
if (count) this.#goTo(this.#current() % count);
|
|
1759
|
+
}
|
|
1760
|
+
previous() {
|
|
1761
|
+
const count = this.#changes();
|
|
1762
|
+
if (count) this.#goTo(this.#current() <= 1 ? count - 1 : this.#current() - 2);
|
|
1763
|
+
}
|
|
1764
|
+
revealLine(line, side = "modified") {
|
|
1765
|
+
const views = this.#views;
|
|
1766
|
+
if (!views) return;
|
|
1767
|
+
const split = this.effectiveLayout() === "split";
|
|
1768
|
+
const original = side === "original";
|
|
1769
|
+
const view = split && original ? views.original : views.modified;
|
|
1770
|
+
const doc = !split && original ? getOriginalDoc(view.state) : view.state.doc;
|
|
1771
|
+
const own = this.#lineStart(doc, line);
|
|
1772
|
+
const b = original ? this.#map(view, own, true) : own;
|
|
1773
|
+
const a = original ? own : this.#map(views.modified, own, false);
|
|
1774
|
+
this.#uncollapse(views.modified, b);
|
|
1775
|
+
if (split) this.#uncollapse(views.original, a);
|
|
1776
|
+
const pos = original && split ? a : b;
|
|
1777
|
+
view.dispatch({
|
|
1778
|
+
effects: EditorView.scrollIntoView(pos, { y: "center" }),
|
|
1779
|
+
selection: { anchor: pos }
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
#lineStart(doc, line) {
|
|
1783
|
+
const n = Math.min(Math.max(Math.trunc(line) || 1, 1), doc.lines);
|
|
1784
|
+
return doc.line(n).from;
|
|
1785
|
+
}
|
|
1786
|
+
#map(view, pos, fromA) {
|
|
1787
|
+
let delta = 0;
|
|
1788
|
+
for (const chunk of this.#chunks(view)) {
|
|
1789
|
+
const [from, to] = fromA ? [chunk.fromA, chunk.toA] : [chunk.fromB, chunk.toB];
|
|
1790
|
+
if (pos < from) break;
|
|
1791
|
+
if (pos < to) return fromA ? chunk.fromB : chunk.fromA;
|
|
1792
|
+
delta += fromA ? chunk.toB - chunk.fromB - (chunk.toA - chunk.fromA) : chunk.toA - chunk.fromA - (chunk.toB - chunk.fromB);
|
|
1793
|
+
}
|
|
1794
|
+
return Math.max(pos + delta, 0);
|
|
1795
|
+
}
|
|
1796
|
+
#uncollapse(view, pos) {
|
|
1797
|
+
const starts = [];
|
|
1798
|
+
for (const source of view.state.facet(EditorView.decorations)) {
|
|
1799
|
+
if (typeof source === "function") continue;
|
|
1800
|
+
source.between(0, view.state.doc.length, (from, to, deco) => {
|
|
1801
|
+
if (deco.spec.widget?.type === "collapsed-unchanged-code" && from <= pos && pos <= to) starts.push(from);
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
if (starts.length) view.dispatch({ effects: starts.map((from) => uncollapseUnchanged.of(from)) });
|
|
1805
|
+
}
|
|
1806
|
+
#goTo(index) {
|
|
1807
|
+
const view = this.#views?.modified;
|
|
1808
|
+
const chunk = view && this.#chunks(view)[index];
|
|
1809
|
+
if (!view || !chunk) return;
|
|
1810
|
+
view.dispatch({
|
|
1811
|
+
selection: { anchor: chunk.fromB },
|
|
1812
|
+
userEvent: "select.byChunk",
|
|
1813
|
+
effects: EditorView.scrollIntoView(EditorSelection.range(chunk.endB, chunk.fromB), { y: "center" })
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
#indexAt(view) {
|
|
1817
|
+
const head = view.state.selection.main.head;
|
|
1818
|
+
return this.#chunks(view).findIndex((c) => c.fromB <= head && head <= c.endB) + 1;
|
|
1819
|
+
}
|
|
1820
|
+
#chunks(view) {
|
|
1821
|
+
return getChunks(view.state)?.chunks ?? [];
|
|
1822
|
+
}
|
|
1823
|
+
#collapse() {
|
|
1824
|
+
const value = this.collapseUnchanged();
|
|
1825
|
+
if (value === false) return null;
|
|
1826
|
+
if (value === true) return DEFAULT_COLLAPSE;
|
|
1827
|
+
return {
|
|
1828
|
+
...DEFAULT_COLLAPSE,
|
|
1829
|
+
...value
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
#labels() {
|
|
1833
|
+
const attributes = { "aria-readonly": "true" };
|
|
1834
|
+
const label = this.ariaLabel();
|
|
1835
|
+
const labelledby = this.ariaLabelledby();
|
|
1836
|
+
if (label) attributes["aria-label"] = label;
|
|
1837
|
+
if (labelledby) attributes["aria-labelledby"] = labelledby;
|
|
1838
|
+
return EditorView.contentAttributes.of(attributes);
|
|
1839
|
+
}
|
|
1840
|
+
get #reviewing() {
|
|
1841
|
+
return this.#views !== null && this.#views.original === this.#views.modified && this.#reviewMode;
|
|
1842
|
+
}
|
|
1843
|
+
#shared(labels) {
|
|
1844
|
+
return [
|
|
1845
|
+
hxCodeTheme(),
|
|
1846
|
+
hxCodeHighlight(),
|
|
1847
|
+
hxDiffTheme(),
|
|
1848
|
+
EditorState.readOnly.of(true),
|
|
1849
|
+
EditorView.editable.of(false),
|
|
1850
|
+
lineNumbers(),
|
|
1851
|
+
this.#language.of([]),
|
|
1852
|
+
this.#review.of([]),
|
|
1853
|
+
this.#findingExtension,
|
|
1854
|
+
this.#threadExtension,
|
|
1855
|
+
EditorView.updateListener.of((update) => {
|
|
1856
|
+
if (update.selectionSet && !update.docChanged && update.view === this.#views?.modified) this.#current.set(this.#indexAt(update.view));
|
|
1857
|
+
}),
|
|
1858
|
+
labels
|
|
1859
|
+
];
|
|
1860
|
+
}
|
|
1861
|
+
#build(layout, original, modified, collapse, labels, reviewable) {
|
|
1862
|
+
this.#reviewMode = reviewable;
|
|
1863
|
+
const parent = this.container().nativeElement;
|
|
1864
|
+
const collapseUnchanged = collapse ?? void 0;
|
|
1865
|
+
if (layout === "unified") {
|
|
1866
|
+
const view = new EditorView({
|
|
1867
|
+
parent,
|
|
1868
|
+
doc: modified,
|
|
1869
|
+
extensions: [...this.#shared(labels), unifiedMergeView({
|
|
1870
|
+
original,
|
|
1871
|
+
mergeControls: reviewable ? (type) => this.#control(type) : false,
|
|
1872
|
+
gutter: true,
|
|
1873
|
+
highlightChanges: true,
|
|
1874
|
+
collapseUnchanged
|
|
1875
|
+
})]
|
|
1876
|
+
});
|
|
1877
|
+
this.#destroy = () => view.destroy();
|
|
1878
|
+
this.#views = {
|
|
1879
|
+
original: view,
|
|
1880
|
+
modified: view
|
|
1881
|
+
};
|
|
1882
|
+
return [view];
|
|
1883
|
+
}
|
|
1884
|
+
const extensions = this.#shared(labels);
|
|
1885
|
+
const merge = new MergeView({
|
|
1886
|
+
parent,
|
|
1887
|
+
a: {
|
|
1888
|
+
doc: original,
|
|
1889
|
+
extensions
|
|
1890
|
+
},
|
|
1891
|
+
b: {
|
|
1892
|
+
doc: modified,
|
|
1893
|
+
extensions
|
|
1894
|
+
},
|
|
1895
|
+
gutter: true,
|
|
1896
|
+
highlightChanges: true,
|
|
1897
|
+
collapseUnchanged
|
|
1898
|
+
});
|
|
1899
|
+
this.#destroy = () => merge.destroy();
|
|
1900
|
+
this.#views = {
|
|
1901
|
+
original: merge.a,
|
|
1902
|
+
modified: merge.b
|
|
1903
|
+
};
|
|
1904
|
+
return [merge.a, merge.b];
|
|
1905
|
+
}
|
|
1906
|
+
#teardown() {
|
|
1907
|
+
this.#destroy?.();
|
|
1908
|
+
this.#destroy = null;
|
|
1909
|
+
this.#views = null;
|
|
1910
|
+
this.#reviewOn = false;
|
|
1911
|
+
this.#reviewMode = false;
|
|
1912
|
+
this.#undecided = [];
|
|
1913
|
+
this.#changes.set(0);
|
|
1914
|
+
this.#current.set(0);
|
|
1915
|
+
}
|
|
1916
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1917
|
+
minVersion: "12.0.0",
|
|
1918
|
+
version: "22.3.0",
|
|
1919
|
+
ngImport: i0,
|
|
1920
|
+
type: HxDiffView,
|
|
1921
|
+
deps: [],
|
|
1922
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1923
|
+
});
|
|
1924
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1925
|
+
minVersion: "17.2.0",
|
|
1926
|
+
version: "22.3.0",
|
|
1927
|
+
type: HxDiffView,
|
|
1928
|
+
isStandalone: true,
|
|
1929
|
+
selector: "hx-diff-view",
|
|
1930
|
+
inputs: {
|
|
1931
|
+
original: {
|
|
1932
|
+
classPropertyName: "original",
|
|
1933
|
+
publicName: "original",
|
|
1934
|
+
isSignal: true,
|
|
1935
|
+
isRequired: true,
|
|
1936
|
+
transformFunction: null
|
|
1937
|
+
},
|
|
1938
|
+
modified: {
|
|
1939
|
+
classPropertyName: "modified",
|
|
1940
|
+
publicName: "modified",
|
|
1941
|
+
isSignal: true,
|
|
1942
|
+
isRequired: true,
|
|
1943
|
+
transformFunction: null
|
|
1944
|
+
},
|
|
1945
|
+
path: {
|
|
1946
|
+
classPropertyName: "path",
|
|
1947
|
+
publicName: "path",
|
|
1948
|
+
isSignal: true,
|
|
1949
|
+
isRequired: false,
|
|
1950
|
+
transformFunction: null
|
|
1951
|
+
},
|
|
1952
|
+
layout: {
|
|
1953
|
+
classPropertyName: "layout",
|
|
1954
|
+
publicName: "layout",
|
|
1955
|
+
isSignal: true,
|
|
1956
|
+
isRequired: false,
|
|
1957
|
+
transformFunction: null
|
|
1958
|
+
},
|
|
1959
|
+
splitMinWidth: {
|
|
1960
|
+
classPropertyName: "splitMinWidth",
|
|
1961
|
+
publicName: "splitMinWidth",
|
|
1962
|
+
isSignal: true,
|
|
1963
|
+
isRequired: false,
|
|
1964
|
+
transformFunction: null
|
|
1965
|
+
},
|
|
1966
|
+
collapseUnchanged: {
|
|
1967
|
+
classPropertyName: "collapseUnchanged",
|
|
1968
|
+
publicName: "collapseUnchanged",
|
|
1969
|
+
isSignal: true,
|
|
1970
|
+
isRequired: false,
|
|
1971
|
+
transformFunction: null
|
|
1972
|
+
},
|
|
1973
|
+
comments: {
|
|
1974
|
+
classPropertyName: "comments",
|
|
1975
|
+
publicName: "comments",
|
|
1976
|
+
isSignal: true,
|
|
1977
|
+
isRequired: false,
|
|
1978
|
+
transformFunction: null
|
|
1979
|
+
},
|
|
1980
|
+
commentable: {
|
|
1981
|
+
classPropertyName: "commentable",
|
|
1982
|
+
publicName: "commentable",
|
|
1983
|
+
isSignal: true,
|
|
1984
|
+
isRequired: false,
|
|
1985
|
+
transformFunction: null
|
|
1986
|
+
},
|
|
1987
|
+
findings: {
|
|
1988
|
+
classPropertyName: "findings",
|
|
1989
|
+
publicName: "findings",
|
|
1990
|
+
isSignal: true,
|
|
1991
|
+
isRequired: false,
|
|
1992
|
+
transformFunction: null
|
|
1993
|
+
},
|
|
1994
|
+
findingActionLabel: {
|
|
1995
|
+
classPropertyName: "findingActionLabel",
|
|
1996
|
+
publicName: "findingActionLabel",
|
|
1997
|
+
isSignal: true,
|
|
1998
|
+
isRequired: false,
|
|
1999
|
+
transformFunction: null
|
|
2000
|
+
},
|
|
2001
|
+
threads: {
|
|
2002
|
+
classPropertyName: "threads",
|
|
2003
|
+
publicName: "threads",
|
|
2004
|
+
isSignal: true,
|
|
2005
|
+
isRequired: false,
|
|
2006
|
+
transformFunction: null
|
|
2007
|
+
},
|
|
2008
|
+
renderComment: {
|
|
2009
|
+
classPropertyName: "renderComment",
|
|
2010
|
+
publicName: "renderComment",
|
|
2011
|
+
isSignal: true,
|
|
2012
|
+
isRequired: false,
|
|
2013
|
+
transformFunction: null
|
|
2014
|
+
},
|
|
2015
|
+
reviewable: {
|
|
2016
|
+
classPropertyName: "reviewable",
|
|
2017
|
+
publicName: "reviewable",
|
|
2018
|
+
isSignal: true,
|
|
2019
|
+
isRequired: false,
|
|
2020
|
+
transformFunction: null
|
|
2021
|
+
},
|
|
2022
|
+
ariaLabel: {
|
|
2023
|
+
classPropertyName: "ariaLabel",
|
|
2024
|
+
publicName: "aria-label",
|
|
2025
|
+
isSignal: true,
|
|
2026
|
+
isRequired: false,
|
|
2027
|
+
transformFunction: null
|
|
2028
|
+
},
|
|
2029
|
+
ariaLabelledby: {
|
|
2030
|
+
classPropertyName: "ariaLabelledby",
|
|
2031
|
+
publicName: "aria-labelledby",
|
|
2032
|
+
isSignal: true,
|
|
2033
|
+
isRequired: false,
|
|
2034
|
+
transformFunction: null
|
|
2035
|
+
}
|
|
2036
|
+
},
|
|
2037
|
+
outputs: {
|
|
2038
|
+
findingAction: "findingAction",
|
|
2039
|
+
replyAdded: "replyAdded",
|
|
2040
|
+
resolvedChange: "resolvedChange",
|
|
2041
|
+
commentAdded: "commentAdded",
|
|
2042
|
+
changeDecided: "changeDecided"
|
|
2043
|
+
},
|
|
2044
|
+
host: {
|
|
2045
|
+
properties: {
|
|
2046
|
+
"attr.aria-label": "null",
|
|
2047
|
+
"attr.aria-labelledby": "null"
|
|
2048
|
+
},
|
|
2049
|
+
classAttribute: "hx-diff-view"
|
|
2050
|
+
},
|
|
2051
|
+
viewQueries: [{
|
|
2052
|
+
propertyName: "container",
|
|
2053
|
+
first: true,
|
|
2054
|
+
predicate: ["container"],
|
|
2055
|
+
descendants: true,
|
|
2056
|
+
isSignal: true
|
|
2057
|
+
}],
|
|
2058
|
+
ngImport: i0,
|
|
2059
|
+
template: "<div #container class=\"hx-diff-view-container\"></div>\n",
|
|
2060
|
+
styles: [":host{display:block;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px);overflow:hidden}.hx-diff-view-container ::ng-deep .cm-mergeView{width:100%}.hx-diff-view-container ::ng-deep .cm-mergeViewEditors>div+div{border-left:1px solid var(--h-content-border-color)}\n"],
|
|
2061
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2062
|
+
});
|
|
2063
|
+
};
|
|
2064
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2065
|
+
minVersion: "12.0.0",
|
|
2066
|
+
version: "22.3.0",
|
|
2067
|
+
ngImport: i0,
|
|
2068
|
+
type: HxDiffView,
|
|
2069
|
+
decorators: [{
|
|
2070
|
+
type: Component,
|
|
2071
|
+
args: [{
|
|
2072
|
+
selector: "hx-diff-view",
|
|
2073
|
+
encapsulation: ViewEncapsulation.Emulated,
|
|
2074
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2075
|
+
host: {
|
|
2076
|
+
class: "hx-diff-view",
|
|
2077
|
+
"[attr.aria-label]": "null",
|
|
2078
|
+
"[attr.aria-labelledby]": "null"
|
|
2079
|
+
},
|
|
2080
|
+
template: "<div #container class=\"hx-diff-view-container\"></div>\n",
|
|
2081
|
+
styles: [":host{display:block;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px);overflow:hidden}.hx-diff-view-container ::ng-deep .cm-mergeView{width:100%}.hx-diff-view-container ::ng-deep .cm-mergeViewEditors>div+div{border-left:1px solid var(--h-content-border-color)}\n"]
|
|
2082
|
+
}]
|
|
2083
|
+
}],
|
|
2084
|
+
ctorParameters: () => [],
|
|
2085
|
+
propDecorators: {
|
|
2086
|
+
original: [{
|
|
2087
|
+
type: i0.Input,
|
|
2088
|
+
args: [{
|
|
2089
|
+
isSignal: true,
|
|
2090
|
+
alias: "original",
|
|
2091
|
+
required: true
|
|
2092
|
+
}]
|
|
2093
|
+
}],
|
|
2094
|
+
modified: [{
|
|
2095
|
+
type: i0.Input,
|
|
2096
|
+
args: [{
|
|
2097
|
+
isSignal: true,
|
|
2098
|
+
alias: "modified",
|
|
2099
|
+
required: true
|
|
2100
|
+
}]
|
|
2101
|
+
}],
|
|
2102
|
+
path: [{
|
|
2103
|
+
type: i0.Input,
|
|
2104
|
+
args: [{
|
|
2105
|
+
isSignal: true,
|
|
2106
|
+
alias: "path",
|
|
2107
|
+
required: false
|
|
2108
|
+
}]
|
|
2109
|
+
}],
|
|
2110
|
+
layout: [{
|
|
2111
|
+
type: i0.Input,
|
|
2112
|
+
args: [{
|
|
2113
|
+
isSignal: true,
|
|
2114
|
+
alias: "layout",
|
|
2115
|
+
required: false
|
|
2116
|
+
}]
|
|
2117
|
+
}],
|
|
2118
|
+
splitMinWidth: [{
|
|
2119
|
+
type: i0.Input,
|
|
2120
|
+
args: [{
|
|
2121
|
+
isSignal: true,
|
|
2122
|
+
alias: "splitMinWidth",
|
|
2123
|
+
required: false
|
|
2124
|
+
}]
|
|
2125
|
+
}],
|
|
2126
|
+
collapseUnchanged: [{
|
|
2127
|
+
type: i0.Input,
|
|
2128
|
+
args: [{
|
|
2129
|
+
isSignal: true,
|
|
2130
|
+
alias: "collapseUnchanged",
|
|
2131
|
+
required: false
|
|
2132
|
+
}]
|
|
2133
|
+
}],
|
|
2134
|
+
comments: [{
|
|
2135
|
+
type: i0.Input,
|
|
2136
|
+
args: [{
|
|
2137
|
+
isSignal: true,
|
|
2138
|
+
alias: "comments",
|
|
2139
|
+
required: false
|
|
2140
|
+
}]
|
|
2141
|
+
}],
|
|
2142
|
+
commentable: [{
|
|
2143
|
+
type: i0.Input,
|
|
2144
|
+
args: [{
|
|
2145
|
+
isSignal: true,
|
|
2146
|
+
alias: "commentable",
|
|
2147
|
+
required: false
|
|
2148
|
+
}]
|
|
2149
|
+
}],
|
|
2150
|
+
findings: [{
|
|
2151
|
+
type: i0.Input,
|
|
2152
|
+
args: [{
|
|
2153
|
+
isSignal: true,
|
|
2154
|
+
alias: "findings",
|
|
2155
|
+
required: false
|
|
2156
|
+
}]
|
|
2157
|
+
}],
|
|
2158
|
+
findingActionLabel: [{
|
|
2159
|
+
type: i0.Input,
|
|
2160
|
+
args: [{
|
|
2161
|
+
isSignal: true,
|
|
2162
|
+
alias: "findingActionLabel",
|
|
2163
|
+
required: false
|
|
2164
|
+
}]
|
|
2165
|
+
}],
|
|
2166
|
+
findingAction: [{
|
|
2167
|
+
type: i0.Output,
|
|
2168
|
+
args: ["findingAction"]
|
|
2169
|
+
}],
|
|
2170
|
+
threads: [{
|
|
2171
|
+
type: i0.Input,
|
|
2172
|
+
args: [{
|
|
2173
|
+
isSignal: true,
|
|
2174
|
+
alias: "threads",
|
|
2175
|
+
required: false
|
|
2176
|
+
}]
|
|
2177
|
+
}],
|
|
2178
|
+
renderComment: [{
|
|
2179
|
+
type: i0.Input,
|
|
2180
|
+
args: [{
|
|
2181
|
+
isSignal: true,
|
|
2182
|
+
alias: "renderComment",
|
|
2183
|
+
required: false
|
|
2184
|
+
}]
|
|
2185
|
+
}],
|
|
2186
|
+
replyAdded: [{
|
|
2187
|
+
type: i0.Output,
|
|
2188
|
+
args: ["replyAdded"]
|
|
2189
|
+
}],
|
|
2190
|
+
resolvedChange: [{
|
|
2191
|
+
type: i0.Output,
|
|
2192
|
+
args: ["resolvedChange"]
|
|
2193
|
+
}],
|
|
2194
|
+
commentAdded: [{
|
|
2195
|
+
type: i0.Output,
|
|
2196
|
+
args: ["commentAdded"]
|
|
2197
|
+
}],
|
|
2198
|
+
reviewable: [{
|
|
2199
|
+
type: i0.Input,
|
|
2200
|
+
args: [{
|
|
2201
|
+
isSignal: true,
|
|
2202
|
+
alias: "reviewable",
|
|
2203
|
+
required: false
|
|
2204
|
+
}]
|
|
2205
|
+
}],
|
|
2206
|
+
changeDecided: [{
|
|
2207
|
+
type: i0.Output,
|
|
2208
|
+
args: ["changeDecided"]
|
|
2209
|
+
}],
|
|
2210
|
+
ariaLabel: [{
|
|
2211
|
+
type: i0.Input,
|
|
2212
|
+
args: [{
|
|
2213
|
+
isSignal: true,
|
|
2214
|
+
alias: "aria-label",
|
|
2215
|
+
required: false
|
|
2216
|
+
}]
|
|
2217
|
+
}],
|
|
2218
|
+
ariaLabelledby: [{
|
|
2219
|
+
type: i0.Input,
|
|
2220
|
+
args: [{
|
|
2221
|
+
isSignal: true,
|
|
2222
|
+
alias: "aria-labelledby",
|
|
2223
|
+
required: false
|
|
2224
|
+
}]
|
|
2225
|
+
}],
|
|
2226
|
+
container: [{
|
|
2227
|
+
type: i0.ViewChild,
|
|
2228
|
+
args: ["container", { isSignal: true }]
|
|
2229
|
+
}]
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2232
|
+
function lcs(a, b) {
|
|
2233
|
+
let head = 0;
|
|
2234
|
+
while (head < a.length && head < b.length && a[head] === b[head]) head++;
|
|
2235
|
+
let tail = 0;
|
|
2236
|
+
while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) tail++;
|
|
2237
|
+
const pairs = [];
|
|
2238
|
+
for (let i = 0; i < head; i++) pairs.push([i, i]);
|
|
2239
|
+
const n = a.length - head - tail;
|
|
2240
|
+
const m = b.length - head - tail;
|
|
2241
|
+
if (n > 0 && m > 0) {
|
|
2242
|
+
if (n * m <= 4e6) {
|
|
2243
|
+
const w = m + 1;
|
|
2244
|
+
const t = new Uint32Array((n + 1) * w);
|
|
2245
|
+
for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) t[i * w + j] = a[head + i] === b[head + j] ? t[(i + 1) * w + j + 1] + 1 : Math.max(t[(i + 1) * w + j], t[i * w + j + 1]);
|
|
2246
|
+
let i = 0;
|
|
2247
|
+
let j = 0;
|
|
2248
|
+
while (i < n && j < m) if (a[head + i] === b[head + j]) {
|
|
2249
|
+
pairs.push([head + i, head + j]);
|
|
2250
|
+
i++;
|
|
2251
|
+
j++;
|
|
2252
|
+
} else if (t[(i + 1) * w + j] >= t[i * w + j + 1]) i++;
|
|
2253
|
+
else j++;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
for (let k = tail; k > 0; k--) pairs.push([a.length - k, b.length - k]);
|
|
2257
|
+
return pairs;
|
|
2258
|
+
}
|
|
2259
|
+
function tokenize(line) {
|
|
2260
|
+
return line.match(/\s+|[\p{L}\p{N}_]+|[^\s\p{L}\p{N}_]/gu) ?? [];
|
|
2261
|
+
}
|
|
2262
|
+
function hxWordDiff(oldLine, newLine) {
|
|
2263
|
+
const a = tokenize(oldLine);
|
|
2264
|
+
const b = tokenize(newLine);
|
|
2265
|
+
const pairs = lcs(a, b);
|
|
2266
|
+
const keptA = new Set(pairs.map((p) => p[0]));
|
|
2267
|
+
const keptB = new Set(pairs.map((p) => p[1]));
|
|
2268
|
+
const build = (tokens, kept) => {
|
|
2269
|
+
const out = [];
|
|
2270
|
+
tokens.forEach((text, i) => {
|
|
2271
|
+
const changed = !kept.has(i);
|
|
2272
|
+
const last = out[out.length - 1];
|
|
2273
|
+
if (last?.changed === changed) last.text += text;
|
|
2274
|
+
else out.push({
|
|
2275
|
+
text,
|
|
2276
|
+
changed
|
|
2277
|
+
});
|
|
2278
|
+
});
|
|
2279
|
+
return out;
|
|
2280
|
+
};
|
|
2281
|
+
return {
|
|
2282
|
+
old: build(a, keptA),
|
|
2283
|
+
new: build(b, keptB)
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
function splitLines(text) {
|
|
2287
|
+
if (text === "") return [];
|
|
2288
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
2289
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
2290
|
+
return lines;
|
|
2291
|
+
}
|
|
2292
|
+
function hxDiffLines(oldText, newText) {
|
|
2293
|
+
const a = splitLines(oldText);
|
|
2294
|
+
const b = splitLines(newText);
|
|
2295
|
+
const pairs = lcs(a, b);
|
|
2296
|
+
const rows = [];
|
|
2297
|
+
let i = 0;
|
|
2298
|
+
let j = 0;
|
|
2299
|
+
const flush = (ai, bj) => {
|
|
2300
|
+
const removed = a.slice(i, ai);
|
|
2301
|
+
const added = b.slice(j, bj);
|
|
2302
|
+
const paired = Math.min(removed.length, added.length);
|
|
2303
|
+
const delRows = removed.map((text) => ({
|
|
2304
|
+
kind: "del",
|
|
2305
|
+
text
|
|
2306
|
+
}));
|
|
2307
|
+
const addRows = added.map((text) => ({
|
|
2308
|
+
kind: "add",
|
|
2309
|
+
text
|
|
2310
|
+
}));
|
|
2311
|
+
for (let k = 0; k < paired; k++) {
|
|
2312
|
+
const w = hxWordDiff(removed[k], added[k]);
|
|
2313
|
+
delRows[k].segments = w.old;
|
|
2314
|
+
addRows[k].segments = w.new;
|
|
2315
|
+
}
|
|
2316
|
+
rows.push(...delRows, ...addRows);
|
|
2317
|
+
};
|
|
2318
|
+
for (const [pi, pj] of pairs) {
|
|
2319
|
+
flush(pi, pj);
|
|
2320
|
+
rows.push({
|
|
2321
|
+
kind: "same",
|
|
2322
|
+
text: a[pi]
|
|
2323
|
+
});
|
|
2324
|
+
i = pi + 1;
|
|
2325
|
+
j = pj + 1;
|
|
2326
|
+
}
|
|
2327
|
+
flush(a.length, b.length);
|
|
2328
|
+
return rows;
|
|
2329
|
+
}
|
|
2330
|
+
function hxDiffStat(rows) {
|
|
2331
|
+
return {
|
|
2332
|
+
added: rows.filter((r) => r.kind === "add").length,
|
|
2333
|
+
removed: rows.filter((r) => r.kind === "del").length
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
function hxMergeParts(a, b) {
|
|
2337
|
+
const parts = [];
|
|
2338
|
+
let hunks = 0;
|
|
2339
|
+
for (const row of hxDiffLines(a, b)) {
|
|
2340
|
+
const last = parts[parts.length - 1];
|
|
2341
|
+
if (row.kind === "same") {
|
|
2342
|
+
if (last?.kind === "same") last.lines.push(row.text);
|
|
2343
|
+
else parts.push({
|
|
2344
|
+
kind: "same",
|
|
2345
|
+
lines: [row.text]
|
|
2346
|
+
});
|
|
2347
|
+
} else {
|
|
2348
|
+
let hunk = last?.kind === "hunk" ? last : null;
|
|
2349
|
+
if (!hunk) {
|
|
2350
|
+
hunk = {
|
|
2351
|
+
kind: "hunk",
|
|
2352
|
+
index: hunks++,
|
|
2353
|
+
mine: [],
|
|
2354
|
+
theirs: []
|
|
2355
|
+
};
|
|
2356
|
+
parts.push(hunk);
|
|
2357
|
+
}
|
|
2358
|
+
(row.kind === "del" ? hunk.mine : hunk.theirs).push(row.text);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
return parts;
|
|
2362
|
+
}
|
|
2363
|
+
function hxMergeText(parts, choices, endsWithBreak) {
|
|
2364
|
+
const lines = [];
|
|
2365
|
+
for (const part of parts) if (part.kind === "same") lines.push(...part.lines);
|
|
2366
|
+
else {
|
|
2367
|
+
const choice = choices[part.index] ?? "mine";
|
|
2368
|
+
if (choice !== "theirs") lines.push(...part.mine);
|
|
2369
|
+
if (choice !== "mine") lines.push(...part.theirs);
|
|
2370
|
+
}
|
|
2371
|
+
return lines.length > 0 && endsWithBreak ? `${lines.join("\n")}\n` : lines.join("\n");
|
|
2372
|
+
}
|
|
2373
|
+
function hxConflictMarker(line) {
|
|
2374
|
+
if (line.length < 7) return null;
|
|
2375
|
+
const c = line[0];
|
|
2376
|
+
if (c !== "<" && c !== "|" && c !== "=" && c !== ">") return null;
|
|
2377
|
+
for (let i = 1; i < 7; i++) if (line[i] !== c) return null;
|
|
2378
|
+
if (line.length > 7 && line[7] !== " " && line[7] !== " " && line[7] !== "\r") return null;
|
|
2379
|
+
if (c === "=" && line.slice(7).trim() !== "") return null;
|
|
2380
|
+
return c;
|
|
2381
|
+
}
|
|
2382
|
+
const labelOf = (line) => line.slice(7).trim();
|
|
2383
|
+
function hxParseConflicts(text) {
|
|
2384
|
+
return hxParseConflictLines(text.split("\n"));
|
|
2385
|
+
}
|
|
2386
|
+
function hxParseConflictLines(lines) {
|
|
2387
|
+
const found = [];
|
|
2388
|
+
let start = -1;
|
|
2389
|
+
let base = -1;
|
|
2390
|
+
let sep = -1;
|
|
2391
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2392
|
+
const marker = hxConflictMarker(lines[i]);
|
|
2393
|
+
if (marker === null) continue;
|
|
2394
|
+
if (marker === "<") {
|
|
2395
|
+
start = i;
|
|
2396
|
+
base = -1;
|
|
2397
|
+
sep = -1;
|
|
2398
|
+
} else if (start < 0) continue;
|
|
2399
|
+
else if (marker === "|") {
|
|
2400
|
+
if (base >= 0 || sep >= 0) start = -1;
|
|
2401
|
+
else base = i;
|
|
2402
|
+
} else if (marker === "=") {
|
|
2403
|
+
if (sep >= 0) start = -1;
|
|
2404
|
+
else sep = i;
|
|
2405
|
+
} else {
|
|
2406
|
+
if (sep >= 0) found.push({
|
|
2407
|
+
start,
|
|
2408
|
+
end: i,
|
|
2409
|
+
ours: {
|
|
2410
|
+
from: start,
|
|
2411
|
+
to: base >= 0 ? base : sep
|
|
2412
|
+
},
|
|
2413
|
+
...base >= 0 ? { base: {
|
|
2414
|
+
from: base,
|
|
2415
|
+
to: sep
|
|
2416
|
+
} } : {},
|
|
2417
|
+
theirs: {
|
|
2418
|
+
from: sep,
|
|
2419
|
+
to: i
|
|
2420
|
+
},
|
|
2421
|
+
oursLabel: labelOf(lines[start]),
|
|
2422
|
+
...base >= 0 ? { baseLabel: labelOf(lines[base]) } : {},
|
|
2423
|
+
theirsLabel: labelOf(lines[i])
|
|
2424
|
+
});
|
|
2425
|
+
start = -1;
|
|
2426
|
+
}
|
|
2427
|
+
if (start < 0) {
|
|
2428
|
+
base = -1;
|
|
2429
|
+
sep = -1;
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
return found;
|
|
2433
|
+
}
|
|
2434
|
+
const linesOf = (doc) => {
|
|
2435
|
+
const lines = [];
|
|
2436
|
+
for (const line of doc.iterLines()) lines.push(line);
|
|
2437
|
+
return lines;
|
|
2438
|
+
};
|
|
2439
|
+
const hxConflictField = StateField.define({
|
|
2440
|
+
create: (state) => hxParseConflictLines(linesOf(state.doc)),
|
|
2441
|
+
update: (value, tr) => tr.docChanged ? hxParseConflictLines(linesOf(tr.state.doc)) : value
|
|
2442
|
+
});
|
|
2443
|
+
function hxConflictCount(state) {
|
|
2444
|
+
return state.field(hxConflictField, false)?.length ?? 0;
|
|
2445
|
+
}
|
|
2446
|
+
const content = (doc, from, to) => {
|
|
2447
|
+
const out = [];
|
|
2448
|
+
for (let n = from + 2; n <= to; n++) out.push(doc.line(n).text);
|
|
2449
|
+
return out;
|
|
2450
|
+
};
|
|
2451
|
+
function resolution(doc, conflict, choice) {
|
|
2452
|
+
const lines = [...choice === "theirs" ? [] : content(doc, conflict.ours.from, conflict.ours.to), ...choice === "ours" ? [] : content(doc, conflict.theirs.from, conflict.theirs.to)];
|
|
2453
|
+
const first = doc.line(conflict.start + 1);
|
|
2454
|
+
const last = doc.line(conflict.end + 1);
|
|
2455
|
+
if (lines.length > 0) return {
|
|
2456
|
+
from: first.from,
|
|
2457
|
+
to: last.to,
|
|
2458
|
+
insert: lines.join("\n")
|
|
2459
|
+
};
|
|
2460
|
+
if (last.to < doc.length) return {
|
|
2461
|
+
from: first.from,
|
|
2462
|
+
to: last.to + 1,
|
|
2463
|
+
insert: ""
|
|
2464
|
+
};
|
|
2465
|
+
return {
|
|
2466
|
+
from: Math.max(0, first.from - 1),
|
|
2467
|
+
to: last.to,
|
|
2468
|
+
insert: ""
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
function accept(view, start, choice) {
|
|
2472
|
+
const conflict = view.state.field(hxConflictField, false)?.find((c) => c.start === start);
|
|
2473
|
+
if (!conflict) return false;
|
|
2474
|
+
view.dispatch({
|
|
2475
|
+
changes: resolution(view.state.doc, conflict, choice),
|
|
2476
|
+
userEvent: "input.conflict.accept",
|
|
2477
|
+
scrollIntoView: true
|
|
2478
|
+
});
|
|
2479
|
+
return true;
|
|
2480
|
+
}
|
|
2481
|
+
const CHOICES$1 = [
|
|
2482
|
+
{
|
|
2483
|
+
choice: "ours",
|
|
2484
|
+
text: "Accept ours"
|
|
2485
|
+
},
|
|
2486
|
+
{
|
|
2487
|
+
choice: "theirs",
|
|
2488
|
+
text: "Accept theirs"
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
choice: "both",
|
|
2492
|
+
text: "Accept both"
|
|
2493
|
+
}
|
|
2494
|
+
];
|
|
2495
|
+
var ConflictActions = class extends WidgetType {
|
|
2496
|
+
conflict;
|
|
2497
|
+
index;
|
|
2498
|
+
total;
|
|
2499
|
+
constructor(conflict, index, total) {
|
|
2500
|
+
super();
|
|
2501
|
+
this.conflict = conflict;
|
|
2502
|
+
this.index = index;
|
|
2503
|
+
this.total = total;
|
|
2504
|
+
}
|
|
2505
|
+
eq(other) {
|
|
2506
|
+
const a = this.conflict;
|
|
2507
|
+
const b = other.conflict;
|
|
2508
|
+
return a.start === b.start && a.end === b.end && a.oursLabel === b.oursLabel && a.theirsLabel === b.theirsLabel && this.index === other.index && this.total === other.total;
|
|
2509
|
+
}
|
|
2510
|
+
toDOM(view) {
|
|
2511
|
+
const c = this.conflict;
|
|
2512
|
+
const row = document.createElement("div");
|
|
2513
|
+
row.className = "cm-hx-conflict-actions";
|
|
2514
|
+
row.setAttribute("role", "group");
|
|
2515
|
+
row.setAttribute("aria-label", `Conflict ${this.index + 1} of ${this.total}`);
|
|
2516
|
+
const title = document.createElement("span");
|
|
2517
|
+
title.className = "cm-hx-conflict-title";
|
|
2518
|
+
title.textContent = `Conflict ${this.index + 1} of ${this.total}`;
|
|
2519
|
+
row.append(title);
|
|
2520
|
+
for (const { choice, text } of CHOICES$1) {
|
|
2521
|
+
const button = document.createElement("button");
|
|
2522
|
+
button.type = "button";
|
|
2523
|
+
button.className = `cm-hx-conflict-action cm-hx-conflict-action-${choice}`;
|
|
2524
|
+
button.textContent = text;
|
|
2525
|
+
const side = choice === "ours" ? c.oursLabel : choice === "theirs" ? c.theirsLabel : [c.oursLabel, c.theirsLabel].filter(Boolean).join(" and ");
|
|
2526
|
+
button.setAttribute("aria-label", side ? `${text}: ${side}` : text);
|
|
2527
|
+
button.addEventListener("click", () => {
|
|
2528
|
+
accept(view, view.state.doc.lineAt(view.posAtDOM(row)).number - 1, choice);
|
|
2529
|
+
});
|
|
2530
|
+
row.append(button);
|
|
2531
|
+
}
|
|
2532
|
+
return row;
|
|
2533
|
+
}
|
|
2534
|
+
ignoreEvent() {
|
|
2535
|
+
return true;
|
|
2536
|
+
}
|
|
2537
|
+
};
|
|
2538
|
+
const decorate = (state) => {
|
|
2539
|
+
const conflicts = state.field(hxConflictField);
|
|
2540
|
+
const doc = state.doc;
|
|
2541
|
+
const ranges = [];
|
|
2542
|
+
const line = (n, cls) => ranges.push(Decoration.line({ class: cls }).range(doc.line(n + 1).from));
|
|
2543
|
+
conflicts.forEach((c, index) => {
|
|
2544
|
+
ranges.push(Decoration.widget({
|
|
2545
|
+
widget: new ConflictActions(c, index, conflicts.length),
|
|
2546
|
+
block: true,
|
|
2547
|
+
side: -1
|
|
2548
|
+
}).range(doc.line(c.start + 1).from));
|
|
2549
|
+
for (let n = c.start; n <= c.end; n++) if (n === c.ours.from || n === c.theirs.from || n === c.end || n === c.base?.from) line(n, "cm-hx-conflict-marker");
|
|
2550
|
+
else if (n < (c.base?.from ?? c.ours.to)) line(n, "cm-hx-conflict-ours");
|
|
2551
|
+
else if (c.base && n < c.base.to) line(n, "cm-hx-conflict-base");
|
|
2552
|
+
else line(n, "cm-hx-conflict-theirs");
|
|
2553
|
+
});
|
|
2554
|
+
return Decoration.set(ranges, true);
|
|
2555
|
+
};
|
|
2556
|
+
const move = (pick) => (view) => {
|
|
2557
|
+
const conflicts = view.state.field(hxConflictField, false);
|
|
2558
|
+
if (!conflicts?.length) return false;
|
|
2559
|
+
const target = pick(conflicts, view.state.doc.lineAt(view.state.selection.main.head).number - 1) ?? void 0;
|
|
2560
|
+
if (!target) return false;
|
|
2561
|
+
view.dispatch({
|
|
2562
|
+
selection: EditorSelection.cursor(view.state.doc.line(target.start + 1).from),
|
|
2563
|
+
scrollIntoView: true,
|
|
2564
|
+
userEvent: "select"
|
|
2565
|
+
});
|
|
2566
|
+
return true;
|
|
2567
|
+
};
|
|
2568
|
+
const hxNextConflict = move((conflicts, line) => conflicts.find((c) => c.start > line) ?? conflicts[0]);
|
|
2569
|
+
const hxPreviousConflict = move((conflicts, line) => [...conflicts].reverse().find((c) => c.start < line) ?? conflicts[conflicts.length - 1]);
|
|
2570
|
+
function hxConflictMarkers() {
|
|
2571
|
+
return [
|
|
2572
|
+
hxConflictField,
|
|
2573
|
+
EditorView.decorations.compute([hxConflictField], decorate),
|
|
2574
|
+
EditorView.baseTheme({
|
|
2575
|
+
"&light .cm-hx-conflict-ours": { backgroundColor: "var(--hx-code-conflict-ours-bg, rgba(46, 160, 67, 0.16))" },
|
|
2576
|
+
"&dark .cm-hx-conflict-ours": { backgroundColor: "var(--hx-code-conflict-ours-bg, rgba(46, 160, 67, 0.24))" },
|
|
2577
|
+
"&light .cm-hx-conflict-theirs": { backgroundColor: "var(--hx-code-conflict-theirs-bg, rgba(31, 111, 235, 0.16))" },
|
|
2578
|
+
"&dark .cm-hx-conflict-theirs": { backgroundColor: "var(--hx-code-conflict-theirs-bg, rgba(56, 139, 253, 0.26))" },
|
|
2579
|
+
".cm-hx-conflict-base": { backgroundColor: "rgba(128, 128, 128, 0.14)" },
|
|
2580
|
+
".cm-hx-conflict-marker": {
|
|
2581
|
+
opacity: "var(--hx-code-conflict-marker-opacity, 0.6)",
|
|
2582
|
+
fontStyle: "italic"
|
|
2583
|
+
},
|
|
2584
|
+
".cm-hx-conflict-actions": {
|
|
2585
|
+
display: "flex",
|
|
2586
|
+
flexWrap: "wrap",
|
|
2587
|
+
alignItems: "center",
|
|
2588
|
+
gap: "6px",
|
|
2589
|
+
padding: "2px 8px",
|
|
2590
|
+
fontFamily: "inherit",
|
|
2591
|
+
color: "var(--h-text-color)"
|
|
2592
|
+
},
|
|
2593
|
+
".cm-hx-conflict-title": {
|
|
2594
|
+
color: "var(--h-text-muted-color)",
|
|
2595
|
+
fontSize: "0.75em",
|
|
2596
|
+
marginRight: "4px"
|
|
2597
|
+
},
|
|
2598
|
+
".cm-hx-conflict-action": {
|
|
2599
|
+
font: "inherit",
|
|
2600
|
+
fontSize: "0.8em",
|
|
2601
|
+
color: "inherit",
|
|
2602
|
+
background: "transparent",
|
|
2603
|
+
border: "1px solid var(--h-content-border-color)",
|
|
2604
|
+
borderRadius: "var(--h-border-radius, 4px)",
|
|
2605
|
+
padding: "1px 8px",
|
|
2606
|
+
cursor: "pointer"
|
|
2607
|
+
},
|
|
2608
|
+
".cm-hx-conflict-action:focus-visible": {
|
|
2609
|
+
outline: "2px solid var(--h-primary-color)",
|
|
2610
|
+
outlineOffset: "1px"
|
|
2611
|
+
}
|
|
2612
|
+
})
|
|
2613
|
+
];
|
|
2614
|
+
}
|
|
2615
|
+
let nextId = 0;
|
|
2616
|
+
const CHOICES = [
|
|
2617
|
+
{
|
|
2618
|
+
value: "mine",
|
|
2619
|
+
label: "mine"
|
|
2620
|
+
},
|
|
2621
|
+
{
|
|
2622
|
+
value: "theirs",
|
|
2623
|
+
label: "theirs"
|
|
2624
|
+
},
|
|
2625
|
+
{
|
|
2626
|
+
value: "both",
|
|
2627
|
+
label: "both"
|
|
2628
|
+
}
|
|
2629
|
+
];
|
|
2630
|
+
var HxConflictMerge = class HxConflictMerge {
|
|
2631
|
+
#host = inject(ElementRef);
|
|
2632
|
+
id = `hx-conflict-merge-${nextId++}`;
|
|
2633
|
+
mine = input.required(...ngDevMode ? [{ debugName: "mine" }] : /* istanbul ignore next */ []);
|
|
2634
|
+
theirs = input.required(...ngDevMode ? [{ debugName: "theirs" }] : /* istanbul ignore next */ []);
|
|
2635
|
+
mineLabel = input("Mine", ...ngDevMode ? [{ debugName: "mineLabel" }] : /* istanbul ignore next */ []);
|
|
2636
|
+
theirsLabel = input("Theirs", ...ngDevMode ? [{ debugName: "theirsLabel" }] : /* istanbul ignore next */ []);
|
|
2637
|
+
merged = output();
|
|
2638
|
+
cancelled = output();
|
|
2639
|
+
parts = computed(() => hxMergeParts(this.mine(), this.theirs()), ...ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []);
|
|
2640
|
+
hunks = computed(() => this.parts().filter((part) => part.kind === "hunk"), ...ngDevMode ? [{ debugName: "hunks" }] : /* istanbul ignore next */ []);
|
|
2641
|
+
choices = linkedSignal({
|
|
2642
|
+
...ngDevMode ? { debugName: "choices" } : /* istanbul ignore next */ {},
|
|
2643
|
+
source: this.parts,
|
|
2644
|
+
computation: () => ({})
|
|
2645
|
+
});
|
|
2646
|
+
edit = linkedSignal({
|
|
2647
|
+
...ngDevMode ? { debugName: "edit" } : /* istanbul ignore next */ {},
|
|
2648
|
+
source: this.parts,
|
|
2649
|
+
computation: () => null
|
|
2650
|
+
});
|
|
2651
|
+
pending = linkedSignal({
|
|
2652
|
+
...ngDevMode ? { debugName: "pending" } : /* istanbul ignore next */ {},
|
|
2653
|
+
source: this.parts,
|
|
2654
|
+
computation: () => null
|
|
2655
|
+
});
|
|
2656
|
+
choiceOptions = CHOICES;
|
|
2657
|
+
result = computed(() => hxMergeText(this.parts(), this.choices(), this.mine().endsWith("\n")), ...ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []);
|
|
2658
|
+
unresolved = computed(() => this.hunks().filter((part) => this.choices()[part.index] === void 0).length, ...ngDevMode ? [{ debugName: "unresolved" }] : /* istanbul ignore next */ []);
|
|
2659
|
+
text = computed(() => this.edit() ?? this.result(), ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
2660
|
+
choiceOf(index) {
|
|
2661
|
+
return this.choices()[index] ?? "mine";
|
|
2662
|
+
}
|
|
2663
|
+
choose(index, choice) {
|
|
2664
|
+
if (this.edit() !== null && this.choiceOf(index) !== choice) {
|
|
2665
|
+
this.pending.set({
|
|
2666
|
+
index,
|
|
2667
|
+
choice
|
|
2668
|
+
});
|
|
2669
|
+
this.restoreRadios(index);
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
this.apply(index, choice);
|
|
2673
|
+
}
|
|
2674
|
+
overwrite() {
|
|
2675
|
+
const pending = this.pending();
|
|
2676
|
+
if (!pending) return;
|
|
2677
|
+
this.edit.set(null);
|
|
2678
|
+
this.apply(pending.index, pending.choice);
|
|
2679
|
+
}
|
|
2680
|
+
keepEdit() {
|
|
2681
|
+
const pending = this.pending();
|
|
2682
|
+
this.pending.set(null);
|
|
2683
|
+
if (pending) this.restoreRadios(pending.index);
|
|
2684
|
+
}
|
|
2685
|
+
onEdit(event) {
|
|
2686
|
+
this.edit.set(event.target.value);
|
|
2687
|
+
this.pending.set(null);
|
|
2688
|
+
}
|
|
2689
|
+
confirm() {
|
|
2690
|
+
this.merged.emit(this.text());
|
|
2691
|
+
}
|
|
2692
|
+
lines(lines) {
|
|
2693
|
+
return lines.join("\n");
|
|
2694
|
+
}
|
|
2695
|
+
apply(index, choice) {
|
|
2696
|
+
this.pending.set(null);
|
|
2697
|
+
this.choices.update((choices) => ({
|
|
2698
|
+
...choices,
|
|
2699
|
+
[index]: choice
|
|
2700
|
+
}));
|
|
2701
|
+
}
|
|
2702
|
+
restoreRadios(index) {
|
|
2703
|
+
const current = this.choiceOf(index);
|
|
2704
|
+
for (const radio of this.#host.nativeElement.querySelectorAll(`input[name="${this.id}-${index}"]`)) radio.checked = radio.value === current;
|
|
2705
|
+
}
|
|
2706
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2707
|
+
minVersion: "12.0.0",
|
|
2708
|
+
version: "22.3.0",
|
|
2709
|
+
ngImport: i0,
|
|
2710
|
+
type: HxConflictMerge,
|
|
2711
|
+
deps: [],
|
|
2712
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
2713
|
+
});
|
|
2714
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
2715
|
+
minVersion: "17.0.0",
|
|
2716
|
+
version: "22.3.0",
|
|
2717
|
+
type: HxConflictMerge,
|
|
2718
|
+
isStandalone: true,
|
|
2719
|
+
selector: "hx-conflict-merge",
|
|
2720
|
+
inputs: {
|
|
2721
|
+
mine: {
|
|
2722
|
+
classPropertyName: "mine",
|
|
2723
|
+
publicName: "mine",
|
|
2724
|
+
isSignal: true,
|
|
2725
|
+
isRequired: true,
|
|
2726
|
+
transformFunction: null
|
|
2727
|
+
},
|
|
2728
|
+
theirs: {
|
|
2729
|
+
classPropertyName: "theirs",
|
|
2730
|
+
publicName: "theirs",
|
|
2731
|
+
isSignal: true,
|
|
2732
|
+
isRequired: true,
|
|
2733
|
+
transformFunction: null
|
|
2734
|
+
},
|
|
2735
|
+
mineLabel: {
|
|
2736
|
+
classPropertyName: "mineLabel",
|
|
2737
|
+
publicName: "mineLabel",
|
|
2738
|
+
isSignal: true,
|
|
2739
|
+
isRequired: false,
|
|
2740
|
+
transformFunction: null
|
|
2741
|
+
},
|
|
2742
|
+
theirsLabel: {
|
|
2743
|
+
classPropertyName: "theirsLabel",
|
|
2744
|
+
publicName: "theirsLabel",
|
|
2745
|
+
isSignal: true,
|
|
2746
|
+
isRequired: false,
|
|
2747
|
+
transformFunction: null
|
|
2748
|
+
}
|
|
2749
|
+
},
|
|
2750
|
+
outputs: {
|
|
2751
|
+
merged: "merged",
|
|
2752
|
+
cancelled: "cancelled"
|
|
2753
|
+
},
|
|
2754
|
+
host: { classAttribute: "hx-conflict-merge" },
|
|
2755
|
+
ngImport: i0,
|
|
2756
|
+
template: "<p class=\"hx-conflict-merge-summary\" role=\"status\">\n {{ hunks().length === 1 ? '1 difference' : hunks().length + ' differences' }}\n @if (hunks().length > 0) {\n · {{ unresolved() }} not chosen yet\n }\n</p>\n\n<div class=\"hx-conflict-merge-parts\">\n @for (part of parts(); track $index) {\n @if (part.kind === 'same') {\n <pre class=\"hx-conflict-merge-same\">{{ lines(part.lines) }}</pre>\n } @else {\n <fieldset class=\"hx-conflict-merge-hunk\">\n <legend>Difference {{ part.index + 1 }}</legend>\n <div class=\"hx-conflict-merge-sides\">\n <div class=\"hx-conflict-merge-side hx-conflict-merge-mine\">\n <span class=\"hx-conflict-merge-side-label\">{{ mineLabel() }}</span>\n <pre>{{ lines(part.mine) }}</pre>\n </div>\n <div class=\"hx-conflict-merge-side hx-conflict-merge-theirs\">\n <span class=\"hx-conflict-merge-side-label\">{{ theirsLabel() }}</span>\n <pre>{{ lines(part.theirs) }}</pre>\n </div>\n </div>\n <div\n class=\"hx-conflict-merge-choices\"\n role=\"radiogroup\"\n [attr.aria-label]=\"'Choice for difference ' + (part.index + 1)\"\n >\n @for (option of choiceOptions; track option.value) {\n <label>\n <input\n type=\"radio\"\n [name]=\"id + '-' + part.index\"\n [value]=\"option.value\"\n [checked]=\"choiceOf(part.index) === option.value\"\n (click)=\"choose(part.index, option.value)\"\n />\n {{\n option.value === 'mine'\n ? mineLabel()\n : option.value === 'theirs'\n ? theirsLabel()\n : 'Both'\n }}\n </label>\n }\n </div>\n </fieldset>\n }\n }\n</div>\n\n<div class=\"hx-conflict-merge-result\">\n <label [for]=\"id + '-result'\">Result</label>\n <textarea\n [id]=\"id + '-result'\"\n rows=\"10\"\n spellcheck=\"false\"\n [value]=\"text()\"\n (input)=\"onEdit($event)\"\n ></textarea>\n @if (pending()) {\n <div class=\"hx-conflict-merge-prompt\" role=\"alert\">\n <span>Your edit of the result will be lost. Overwrite it with the new choice?</span>\n <button type=\"button\" class=\"hx-conflict-merge-overwrite\" (click)=\"overwrite()\">\n Overwrite\n </button>\n <button type=\"button\" class=\"hx-conflict-merge-keep\" (click)=\"keepEdit()\">Keep edit</button>\n </div>\n }\n</div>\n\n<div class=\"hx-conflict-merge-actions\">\n <button type=\"button\" class=\"hx-conflict-merge-cancel\" (click)=\"cancelled.emit()\">Cancel</button>\n <button type=\"button\" class=\"hx-conflict-merge-confirm\" (click)=\"confirm()\">Merge</button>\n</div>\n",
|
|
2757
|
+
styles: [":host{display:flex;flex-direction:column;gap:.75rem}pre{margin:0;white-space:pre-wrap;overflow-wrap:anywhere;font-family:var(--h-font-family-mono, ui-monospace, monospace);font-size:.875rem}.hx-conflict-merge-summary{margin:0;color:var(--h-text-muted-color)}.hx-conflict-merge-parts{display:flex;flex-direction:column;gap:.5rem}.hx-conflict-merge-same{padding:0 .5rem;color:var(--h-text-muted-color)}.hx-conflict-merge-hunk{margin:0;padding:.5rem;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px)}.hx-conflict-merge-sides{display:grid;grid-template-columns:1fr 1fr;gap:.5rem}.hx-conflict-merge-side{padding:.25rem .5rem;border-radius:var(--h-border-radius, 6px);background:var(--hx-code-conflict-ours-bg, transparent);min-width:0}.hx-conflict-merge-theirs{background:var(--hx-code-conflict-theirs-bg, transparent)}.hx-conflict-merge-side-label{display:block;font-size:.75rem;font-weight:600}.hx-conflict-merge-choices{display:flex;gap:1rem;margin-top:.5rem}.hx-conflict-merge-result{display:flex;flex-direction:column;gap:.25rem}.hx-conflict-merge-result textarea{width:100%;box-sizing:border-box;font-family:var(--h-font-family-mono, ui-monospace, monospace);font-size:.875rem}.hx-conflict-merge-prompt{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.hx-conflict-merge-actions{display:flex;justify-content:flex-end;gap:.5rem}\n"],
|
|
2758
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2759
|
+
});
|
|
2760
|
+
};
|
|
2761
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2762
|
+
minVersion: "12.0.0",
|
|
2763
|
+
version: "22.3.0",
|
|
2764
|
+
ngImport: i0,
|
|
2765
|
+
type: HxConflictMerge,
|
|
2766
|
+
decorators: [{
|
|
2767
|
+
type: Component,
|
|
2768
|
+
args: [{
|
|
2769
|
+
selector: "hx-conflict-merge",
|
|
2770
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2771
|
+
host: { class: "hx-conflict-merge" },
|
|
2772
|
+
template: "<p class=\"hx-conflict-merge-summary\" role=\"status\">\n {{ hunks().length === 1 ? '1 difference' : hunks().length + ' differences' }}\n @if (hunks().length > 0) {\n · {{ unresolved() }} not chosen yet\n }\n</p>\n\n<div class=\"hx-conflict-merge-parts\">\n @for (part of parts(); track $index) {\n @if (part.kind === 'same') {\n <pre class=\"hx-conflict-merge-same\">{{ lines(part.lines) }}</pre>\n } @else {\n <fieldset class=\"hx-conflict-merge-hunk\">\n <legend>Difference {{ part.index + 1 }}</legend>\n <div class=\"hx-conflict-merge-sides\">\n <div class=\"hx-conflict-merge-side hx-conflict-merge-mine\">\n <span class=\"hx-conflict-merge-side-label\">{{ mineLabel() }}</span>\n <pre>{{ lines(part.mine) }}</pre>\n </div>\n <div class=\"hx-conflict-merge-side hx-conflict-merge-theirs\">\n <span class=\"hx-conflict-merge-side-label\">{{ theirsLabel() }}</span>\n <pre>{{ lines(part.theirs) }}</pre>\n </div>\n </div>\n <div\n class=\"hx-conflict-merge-choices\"\n role=\"radiogroup\"\n [attr.aria-label]=\"'Choice for difference ' + (part.index + 1)\"\n >\n @for (option of choiceOptions; track option.value) {\n <label>\n <input\n type=\"radio\"\n [name]=\"id + '-' + part.index\"\n [value]=\"option.value\"\n [checked]=\"choiceOf(part.index) === option.value\"\n (click)=\"choose(part.index, option.value)\"\n />\n {{\n option.value === 'mine'\n ? mineLabel()\n : option.value === 'theirs'\n ? theirsLabel()\n : 'Both'\n }}\n </label>\n }\n </div>\n </fieldset>\n }\n }\n</div>\n\n<div class=\"hx-conflict-merge-result\">\n <label [for]=\"id + '-result'\">Result</label>\n <textarea\n [id]=\"id + '-result'\"\n rows=\"10\"\n spellcheck=\"false\"\n [value]=\"text()\"\n (input)=\"onEdit($event)\"\n ></textarea>\n @if (pending()) {\n <div class=\"hx-conflict-merge-prompt\" role=\"alert\">\n <span>Your edit of the result will be lost. Overwrite it with the new choice?</span>\n <button type=\"button\" class=\"hx-conflict-merge-overwrite\" (click)=\"overwrite()\">\n Overwrite\n </button>\n <button type=\"button\" class=\"hx-conflict-merge-keep\" (click)=\"keepEdit()\">Keep edit</button>\n </div>\n }\n</div>\n\n<div class=\"hx-conflict-merge-actions\">\n <button type=\"button\" class=\"hx-conflict-merge-cancel\" (click)=\"cancelled.emit()\">Cancel</button>\n <button type=\"button\" class=\"hx-conflict-merge-confirm\" (click)=\"confirm()\">Merge</button>\n</div>\n",
|
|
2773
|
+
styles: [":host{display:flex;flex-direction:column;gap:.75rem}pre{margin:0;white-space:pre-wrap;overflow-wrap:anywhere;font-family:var(--h-font-family-mono, ui-monospace, monospace);font-size:.875rem}.hx-conflict-merge-summary{margin:0;color:var(--h-text-muted-color)}.hx-conflict-merge-parts{display:flex;flex-direction:column;gap:.5rem}.hx-conflict-merge-same{padding:0 .5rem;color:var(--h-text-muted-color)}.hx-conflict-merge-hunk{margin:0;padding:.5rem;border:1px solid var(--h-content-border-color);border-radius:var(--h-border-radius, 6px)}.hx-conflict-merge-sides{display:grid;grid-template-columns:1fr 1fr;gap:.5rem}.hx-conflict-merge-side{padding:.25rem .5rem;border-radius:var(--h-border-radius, 6px);background:var(--hx-code-conflict-ours-bg, transparent);min-width:0}.hx-conflict-merge-theirs{background:var(--hx-code-conflict-theirs-bg, transparent)}.hx-conflict-merge-side-label{display:block;font-size:.75rem;font-weight:600}.hx-conflict-merge-choices{display:flex;gap:1rem;margin-top:.5rem}.hx-conflict-merge-result{display:flex;flex-direction:column;gap:.25rem}.hx-conflict-merge-result textarea{width:100%;box-sizing:border-box;font-family:var(--h-font-family-mono, ui-monospace, monospace);font-size:.875rem}.hx-conflict-merge-prompt{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.hx-conflict-merge-actions{display:flex;justify-content:flex-end;gap:.5rem}\n"]
|
|
2774
|
+
}]
|
|
2775
|
+
}],
|
|
2776
|
+
propDecorators: {
|
|
2777
|
+
mine: [{
|
|
2778
|
+
type: i0.Input,
|
|
2779
|
+
args: [{
|
|
2780
|
+
isSignal: true,
|
|
2781
|
+
alias: "mine",
|
|
2782
|
+
required: true
|
|
2783
|
+
}]
|
|
2784
|
+
}],
|
|
2785
|
+
theirs: [{
|
|
2786
|
+
type: i0.Input,
|
|
2787
|
+
args: [{
|
|
2788
|
+
isSignal: true,
|
|
2789
|
+
alias: "theirs",
|
|
2790
|
+
required: true
|
|
2791
|
+
}]
|
|
2792
|
+
}],
|
|
2793
|
+
mineLabel: [{
|
|
2794
|
+
type: i0.Input,
|
|
2795
|
+
args: [{
|
|
2796
|
+
isSignal: true,
|
|
2797
|
+
alias: "mineLabel",
|
|
2798
|
+
required: false
|
|
2799
|
+
}]
|
|
2800
|
+
}],
|
|
2801
|
+
theirsLabel: [{
|
|
2802
|
+
type: i0.Input,
|
|
2803
|
+
args: [{
|
|
2804
|
+
isSignal: true,
|
|
2805
|
+
alias: "theirsLabel",
|
|
2806
|
+
required: false
|
|
2807
|
+
}]
|
|
2808
|
+
}],
|
|
2809
|
+
merged: [{
|
|
2810
|
+
type: i0.Output,
|
|
2811
|
+
args: ["merged"]
|
|
2812
|
+
}],
|
|
2813
|
+
cancelled: [{
|
|
2814
|
+
type: i0.Output,
|
|
2815
|
+
args: ["cancelled"]
|
|
2816
|
+
}]
|
|
2817
|
+
}
|
|
2818
|
+
});
|
|
2819
|
+
const HELIX_CODE_VERSION = "0.1.0";
|
|
2820
|
+
export { HELIX_CODE_VERSION, HX_CODE_LANGUAGES, HX_CODE_PALETTE, HX_DIFF_PALETTE, HxCodeEditor, HxConflictMerge, HxDiffView, hxCodeHighlight, hxCodeTheme, hxConflictCount, hxConflictField, hxConflictMarkers, hxDiffLines, hxDiffStat, hxDiffTheme, hxLanguageFor, hxLoadLanguage, hxMergeParts, hxMergeText, hxNextConflict, hxParseConflicts, hxPreviousConflict, hxWordDiff, openCommentDraft };
|
|
2821
|
+
|
|
2822
|
+
//# sourceMappingURL=gravionlabs-helix-code.mjs.map
|