@dou-ui/code 0.1.0-alpha.3 → 0.1.0-alpha.30
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/dist/assets/default-BWWFJmzn.js.map +1 -0
- package/dist/code-diff.js.map +1 -1
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +756 -63
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/code-editor.js.map +1 -1
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +784 -474
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extension.js +6 -1
- package/dist/extension.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/language/highlighter.js +1 -1
- package/dist/language/highlighter.js.map +1 -1
- package/dist/language/language.js +24 -2
- package/dist/language/language.js.map +1 -1
- package/dist/language/remote-tokens.js +131 -0
- package/dist/language/remote-tokens.js.map +1 -0
- package/dist/language/worker-client.js +308 -33
- package/dist/language/worker-client.js.map +1 -1
- package/dist/language/worker-protocol.js.map +1 -1
- package/dist/shiki/index.js +54 -3
- package/dist/shiki/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/code-diff.vue.d.ts +18 -21
- package/dist/types/code-editor.vue.d.ts +3 -1
- package/dist/types/extension.d.ts +57 -5
- package/dist/types/index.d.ts +97 -21
- package/dist/types/language/language.d.ts +27 -0
- package/dist/types/language/remote-tokens.d.ts +38 -0
- package/dist/types/language/worker-client.d.ts +85 -15
- package/dist/types/language/worker-protocol.d.ts +53 -2
- package/dist/types/shiki/index.d.ts +36 -1
- package/dist/types/types.d.ts +166 -10
- package/dist/types/view/measure.d.ts +6 -0
- package/dist/types/worker/index.d.ts +27 -12
- package/dist/view/measure.js +23 -5
- package/dist/view/measure.js.map +1 -1
- package/dist/worker/default.js +1 -1
- package/dist/worker/index.js +280 -53
- package/dist/worker/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/assets/default-BZBMZKf_.js.map +0 -1
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { splitLines } from "./core/text.js";
|
|
2
|
+
import { acquirePoolWorker, holdWorker, isCodeWorkerPool, ownWorker, requestWorkerDiff } from "./language/worker-client.js";
|
|
2
3
|
import { format, useCodeMessages } from "./locale.js";
|
|
3
|
-
import { defineCodeExtension } from "./extension.js";
|
|
4
|
+
import { WIDGET_HEIGHT_KEY, defineCodeExtension } from "./extension.js";
|
|
5
|
+
import render_part_default from "./render-part.js";
|
|
4
6
|
import code_editor_default from "./code-editor.js";
|
|
5
7
|
import { diffText, lineStarts } from "./core/diff.js";
|
|
6
8
|
import { DouButton, DouTooltip, createScrollLink, useNamespace } from "dou-ui";
|
|
7
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, onBeforeUnmount, onMounted, openBlock, reactive, ref, toDisplayString, unref, watch, withCtx } from "vue";
|
|
9
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, provide, reactive, ref, renderList, renderSlot, shallowRef, toDisplayString, unref, useSlots, watch, withCtx } from "vue";
|
|
8
10
|
import { ArrowDownIcon, ArrowUpIcon, DiffSplitIcon, DiffUnifiedIcon, FoldVerticalIcon, UnfoldVerticalIcon } from "@dou-ui/icons";
|
|
9
11
|
// src/code-diff.vue?vue&type=script&setup=true&lang.ts
|
|
10
12
|
var _hoisted_1 = ["aria-label"];
|
|
13
|
+
var _hoisted_2 = ["role", "aria-label"];
|
|
11
14
|
/**
|
|
12
15
|
* Two texts compared: side by side, or the changes in one column. Changed
|
|
13
16
|
* lines are tinted, the words that changed inside them marked, and long
|
|
14
17
|
* runs of unchanged lines hidden behind a bar that shows them.
|
|
15
18
|
*/
|
|
16
19
|
var SPLIT_WIDTH = 560;
|
|
20
|
+
/** Below this, inline mode tightens line-number columns and spacing to leave more room for code. */
|
|
21
|
+
var COMPACT_WIDTH = 480;
|
|
17
22
|
var BAR_HEIGHT = 28;
|
|
18
23
|
/** What one side of the split view draws: tints, marks, fillers, hidden lines and bars. */
|
|
19
24
|
var Kind = /* @__PURE__ */ function(Kind) {
|
|
@@ -22,6 +27,11 @@ var Kind = /* @__PURE__ */ function(Kind) {
|
|
|
22
27
|
Kind[Kind["Added"] = 2] = "Added";
|
|
23
28
|
return Kind;
|
|
24
29
|
}(Kind || {});
|
|
30
|
+
var LINE = 20;
|
|
31
|
+
/**
|
|
32
|
+
* Where a spot beside line `line` of `side` is on the other side: beside
|
|
33
|
+
* a line there, or inside the filler of a change.
|
|
34
|
+
*/
|
|
25
35
|
var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
26
36
|
name: "DouCodeDiff",
|
|
27
37
|
__name: "code-diff",
|
|
@@ -29,6 +39,16 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
29
39
|
original: { default: "" },
|
|
30
40
|
modelValue: { default: "" },
|
|
31
41
|
language: { default: void 0 },
|
|
42
|
+
worker: {
|
|
43
|
+
type: [
|
|
44
|
+
Boolean,
|
|
45
|
+
Function,
|
|
46
|
+
Object
|
|
47
|
+
],
|
|
48
|
+
default: false
|
|
49
|
+
},
|
|
50
|
+
syncHighlightLines: { default: void 0 },
|
|
51
|
+
syncDiffLines: { default: 500 },
|
|
32
52
|
mode: { default: "auto" },
|
|
33
53
|
editable: {
|
|
34
54
|
type: Boolean,
|
|
@@ -51,26 +71,39 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
51
71
|
default: false
|
|
52
72
|
},
|
|
53
73
|
extensions: { default: void 0 },
|
|
74
|
+
gutters: { default: void 0 },
|
|
75
|
+
widgets: { default: void 0 },
|
|
54
76
|
tabSize: { default: 2 },
|
|
55
77
|
toolbar: {
|
|
56
78
|
type: Boolean,
|
|
57
79
|
default: true
|
|
58
80
|
},
|
|
81
|
+
stickyToolbar: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false
|
|
84
|
+
},
|
|
59
85
|
bordered: {
|
|
60
86
|
type: Boolean,
|
|
61
87
|
default: true
|
|
62
88
|
},
|
|
89
|
+
scrollY: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: true
|
|
92
|
+
},
|
|
63
93
|
messages: { default: void 0 }
|
|
64
94
|
},
|
|
65
95
|
emits: ["update:modelValue", "update:mode"],
|
|
66
96
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
67
97
|
const props = __props;
|
|
68
98
|
const emit = __emit;
|
|
99
|
+
const slots = useSlots();
|
|
69
100
|
const ns = useNamespace("code-diff");
|
|
70
101
|
const messages = useCodeMessages(() => props.messages);
|
|
71
102
|
const root = ref();
|
|
72
103
|
/** Whether the box is wide enough for two columns. */
|
|
73
104
|
const roomy = ref(true);
|
|
105
|
+
/** Whether the box is narrow enough to use compact inline gutter columns. */
|
|
106
|
+
const compact = ref(false);
|
|
74
107
|
/** The view picked with the toggle, when `mode` isn't bound. */
|
|
75
108
|
const picked = ref(null);
|
|
76
109
|
watch(() => props.mode, () => picked.value = null);
|
|
@@ -85,15 +118,27 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
85
118
|
emit("update:mode", other);
|
|
86
119
|
}
|
|
87
120
|
/** Below this, each side would show fewer than about 30 columns: one column reads better. */
|
|
121
|
+
function syncWidth(width) {
|
|
122
|
+
if (width <= 0) return;
|
|
123
|
+
roomy.value = width >= SPLIT_WIDTH;
|
|
124
|
+
compact.value = width < COMPACT_WIDTH;
|
|
125
|
+
}
|
|
126
|
+
const mounted = ref(false);
|
|
88
127
|
let resize;
|
|
89
128
|
onMounted(() => {
|
|
90
|
-
|
|
129
|
+
mounted.value = true;
|
|
130
|
+
if (!root.value) return;
|
|
131
|
+
syncWidth(root.value.clientWidth);
|
|
132
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
91
133
|
resize = new ResizeObserver(([entry]) => {
|
|
92
|
-
if (entry)
|
|
134
|
+
if (entry) syncWidth(entry.contentRect.width);
|
|
93
135
|
});
|
|
94
136
|
resize.observe(root.value);
|
|
95
137
|
});
|
|
96
|
-
onBeforeUnmount(() =>
|
|
138
|
+
onBeforeUnmount(() => {
|
|
139
|
+
resize?.disconnect();
|
|
140
|
+
stopDiffWorker();
|
|
141
|
+
});
|
|
97
142
|
/** The modified text as edited here, ahead of the parent's copy. */
|
|
98
143
|
const modified = ref(props.modelValue);
|
|
99
144
|
watch(() => props.modelValue, (value) => modified.value = value);
|
|
@@ -101,12 +146,126 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
101
146
|
modified.value = value;
|
|
102
147
|
emit("update:modelValue", value);
|
|
103
148
|
}
|
|
104
|
-
const hunks = computed(() => diffText(props.original, modified.value, {
|
|
105
|
-
ignoreWhitespace: props.ignoreWhitespace,
|
|
106
|
-
words: props.words
|
|
107
|
-
}));
|
|
108
149
|
const originalLines = computed(() => splitLines(props.original));
|
|
109
150
|
const modifiedLines = computed(() => splitLines(modified.value));
|
|
151
|
+
const asyncDiffState = shallowRef(null);
|
|
152
|
+
const diffWorkerFailed = ref(false);
|
|
153
|
+
let diffJob = 0;
|
|
154
|
+
let activeDiffReq = null;
|
|
155
|
+
let activeDiffRelease = null;
|
|
156
|
+
/** Cached factory worker instance for diffs when `worker` is a `() => Worker` function. */
|
|
157
|
+
let fnDiffWorker = null;
|
|
158
|
+
function releaseActiveDiff() {
|
|
159
|
+
activeDiffReq?.cancel();
|
|
160
|
+
activeDiffReq = null;
|
|
161
|
+
activeDiffRelease?.();
|
|
162
|
+
activeDiffRelease = null;
|
|
163
|
+
}
|
|
164
|
+
function stopDiffWorker() {
|
|
165
|
+
diffJob++;
|
|
166
|
+
releaseActiveDiff();
|
|
167
|
+
fnDiffWorker?.release();
|
|
168
|
+
fnDiffWorker = null;
|
|
169
|
+
}
|
|
170
|
+
watch(() => props.worker, () => {
|
|
171
|
+
diffWorkerFailed.value = false;
|
|
172
|
+
stopDiffWorker();
|
|
173
|
+
});
|
|
174
|
+
const useAsyncDiff = computed(() => {
|
|
175
|
+
if (!props.worker || diffWorkerFailed.value || typeof Worker === "undefined") return false;
|
|
176
|
+
if (props.original === modified.value) return false;
|
|
177
|
+
const limit = Math.max(0, props.syncDiffLines);
|
|
178
|
+
return originalLines.value.length + modifiedLines.value.length > limit;
|
|
179
|
+
});
|
|
180
|
+
async function acquireDiffWorker() {
|
|
181
|
+
const option = props.worker;
|
|
182
|
+
if (option === true) return ownWorker();
|
|
183
|
+
if (isCodeWorkerPool(option)) return acquirePoolWorker(option);
|
|
184
|
+
if (typeof option === "function") {
|
|
185
|
+
if (!fnDiffWorker || fnDiffWorker.option !== option) {
|
|
186
|
+
fnDiffWorker?.release();
|
|
187
|
+
const worker = option();
|
|
188
|
+
fnDiffWorker = {
|
|
189
|
+
option,
|
|
190
|
+
worker,
|
|
191
|
+
release: holdWorker(worker)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
worker: fnDiffWorker.worker,
|
|
196
|
+
release: () => {}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
throw new Error("[@dou-ui/code] no worker configured");
|
|
200
|
+
}
|
|
201
|
+
watch([
|
|
202
|
+
useAsyncDiff,
|
|
203
|
+
mounted,
|
|
204
|
+
() => props.original,
|
|
205
|
+
modified,
|
|
206
|
+
() => props.ignoreWhitespace,
|
|
207
|
+
() => props.words,
|
|
208
|
+
() => props.worker
|
|
209
|
+
], ([asyncEnabled, isMounted, original, mod, ignoreWhitespace, words]) => {
|
|
210
|
+
const job = ++diffJob;
|
|
211
|
+
releaseActiveDiff();
|
|
212
|
+
const current = asyncDiffState.value;
|
|
213
|
+
if (!asyncEnabled || !current || current.original !== original || current.modified !== mod || current.ignoreWhitespace !== ignoreWhitespace || current.words !== words) {
|
|
214
|
+
if (current) asyncDiffState.value = null;
|
|
215
|
+
}
|
|
216
|
+
if (!asyncEnabled || !isMounted) return;
|
|
217
|
+
acquireDiffWorker().then(({ worker, release, setBusy }) => {
|
|
218
|
+
if (job !== diffJob) {
|
|
219
|
+
release();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
setBusy?.(true);
|
|
223
|
+
const finish = () => {
|
|
224
|
+
setBusy?.(false);
|
|
225
|
+
release();
|
|
226
|
+
};
|
|
227
|
+
activeDiffRelease = finish;
|
|
228
|
+
const req = requestWorkerDiff(worker, original, mod, {
|
|
229
|
+
ignoreWhitespace,
|
|
230
|
+
words
|
|
231
|
+
});
|
|
232
|
+
activeDiffReq = req;
|
|
233
|
+
req.promise.then((result) => {
|
|
234
|
+
if (job !== diffJob) return;
|
|
235
|
+
activeDiffReq = null;
|
|
236
|
+
activeDiffRelease = null;
|
|
237
|
+
finish();
|
|
238
|
+
asyncDiffState.value = {
|
|
239
|
+
hunks: result,
|
|
240
|
+
original,
|
|
241
|
+
modified: mod,
|
|
242
|
+
ignoreWhitespace,
|
|
243
|
+
words
|
|
244
|
+
};
|
|
245
|
+
}, () => {
|
|
246
|
+
if (job !== diffJob) return;
|
|
247
|
+
activeDiffReq = null;
|
|
248
|
+
activeDiffRelease = null;
|
|
249
|
+
finish();
|
|
250
|
+
diffWorkerFailed.value = true;
|
|
251
|
+
});
|
|
252
|
+
}, () => {
|
|
253
|
+
if (job !== diffJob) return;
|
|
254
|
+
diffWorkerFailed.value = true;
|
|
255
|
+
});
|
|
256
|
+
}, { immediate: true });
|
|
257
|
+
const hunks = computed(() => {
|
|
258
|
+
if (props.original === modified.value) return [];
|
|
259
|
+
if (useAsyncDiff.value) {
|
|
260
|
+
const state = asyncDiffState.value;
|
|
261
|
+
if (!state || state.original !== props.original || state.modified !== modified.value || state.ignoreWhitespace !== props.ignoreWhitespace || state.words !== props.words) return [];
|
|
262
|
+
return state.hunks;
|
|
263
|
+
}
|
|
264
|
+
return diffText(props.original, modified.value, {
|
|
265
|
+
ignoreWhitespace: props.ignoreWhitespace,
|
|
266
|
+
words: props.words
|
|
267
|
+
});
|
|
268
|
+
});
|
|
110
269
|
const stats = computed(() => {
|
|
111
270
|
let added = 0;
|
|
112
271
|
let removed = 0;
|
|
@@ -131,45 +290,74 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
131
290
|
/** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */
|
|
132
291
|
const opened = reactive(/* @__PURE__ */ new Set());
|
|
133
292
|
const allOpen = ref(false);
|
|
293
|
+
/**
|
|
294
|
+
* The lines with a marker or widget on each side, which collapsing leaves in
|
|
295
|
+
* view. A marker shown only on hover is out of sight, so it doesn't count.
|
|
296
|
+
*/
|
|
297
|
+
const annotatedLines = computed(() => {
|
|
298
|
+
const out = {
|
|
299
|
+
a: /* @__PURE__ */ new Set(),
|
|
300
|
+
b: /* @__PURE__ */ new Set()
|
|
301
|
+
};
|
|
302
|
+
const add = (side, line) => out[side === "original" ? "a" : "b"].add(line);
|
|
303
|
+
for (const gutter of props.gutters ?? []) for (const marker of gutter.markers ?? []) if (marker.visible !== "hover") add(marker.side, marker.line);
|
|
304
|
+
for (const widget of props.widgets ?? []) add(widget.side, widget.line);
|
|
305
|
+
return out;
|
|
306
|
+
});
|
|
134
307
|
const unchanged = computed(() => {
|
|
135
308
|
const list = hunks.value;
|
|
136
|
-
const total = originalLines.value.length;
|
|
309
|
+
const total = list.length ? originalLines.value.length : Math.min(originalLines.value.length, modifiedLines.value.length);
|
|
137
310
|
const out = [];
|
|
138
311
|
const rule = collapse.value;
|
|
139
312
|
const push = (a, b, count, before, after) => {
|
|
140
313
|
if (count <= 0) return;
|
|
314
|
+
let hideable = false;
|
|
141
315
|
let hideFrom = 0;
|
|
142
316
|
let hideCount = 0;
|
|
143
|
-
if (rule && list.length
|
|
317
|
+
if (rule && list.length) {
|
|
144
318
|
const from = before ? rule.context : 0;
|
|
145
319
|
const to = count - (after ? rule.context : 0);
|
|
146
320
|
if (to - from >= rule.minLines) {
|
|
147
|
-
|
|
148
|
-
|
|
321
|
+
hideable = true;
|
|
322
|
+
if (!allOpen.value && !opened.has(a)) {
|
|
323
|
+
hideFrom = from;
|
|
324
|
+
hideCount = to - from;
|
|
325
|
+
}
|
|
149
326
|
}
|
|
150
327
|
}
|
|
151
328
|
out.push({
|
|
152
329
|
a,
|
|
153
330
|
b,
|
|
154
331
|
count,
|
|
332
|
+
hideable,
|
|
155
333
|
hideFrom,
|
|
156
334
|
hideCount,
|
|
157
335
|
key: a
|
|
158
336
|
});
|
|
159
337
|
};
|
|
338
|
+
const kept = annotatedLines.value;
|
|
339
|
+
const cut = (a, b, count, before, after) => {
|
|
340
|
+
let from = 0;
|
|
341
|
+
for (let i = 0; i < count; i++) {
|
|
342
|
+
if (!kept.a.has(a + i) && !kept.b.has(b + i)) continue;
|
|
343
|
+
if (i > from) push(a + from, b + from, i - from, from > 0 || before, true);
|
|
344
|
+
from = Math.max(from, i);
|
|
345
|
+
}
|
|
346
|
+
push(a + from, b + from, count - from, from > 0 || before, after);
|
|
347
|
+
};
|
|
160
348
|
let a = 1;
|
|
161
349
|
let b = 1;
|
|
162
350
|
for (let i = 0; i < list.length; i++) {
|
|
163
351
|
const hunk = list[i];
|
|
164
|
-
|
|
352
|
+
cut(a, b, hunk.originalStart - a, i > 0, true);
|
|
165
353
|
a = hunk.originalStart + hunk.originalCount;
|
|
166
354
|
b = hunk.modifiedStart + hunk.modifiedCount;
|
|
167
355
|
}
|
|
168
|
-
|
|
356
|
+
cut(a, b, total - a + 1, list.length > 0, false);
|
|
169
357
|
return out;
|
|
170
358
|
});
|
|
171
359
|
const hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0));
|
|
172
|
-
const anyHideable = computed(() =>
|
|
360
|
+
const anyHideable = computed(() => unchanged.value.some((run) => run.hideable));
|
|
173
361
|
function open(key) {
|
|
174
362
|
opened.add(key);
|
|
175
363
|
}
|
|
@@ -233,43 +421,23 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
233
421
|
}
|
|
234
422
|
return out;
|
|
235
423
|
},
|
|
236
|
-
gutters: [{
|
|
237
|
-
name: "diff",
|
|
238
|
-
width: 16,
|
|
239
|
-
markers({ visible }) {
|
|
240
|
-
const out = [];
|
|
241
|
-
const title = side === "a" ? messages.value.diffRemoved : messages.value.diffAdded;
|
|
242
|
-
for (const hunk of hunks.value) {
|
|
243
|
-
const start = startOf(hunk);
|
|
244
|
-
const count = countOf(hunk);
|
|
245
|
-
if (start > visible.to) break;
|
|
246
|
-
for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++) out.push({
|
|
247
|
-
line: n,
|
|
248
|
-
text: side === "a" ? "−" : "+",
|
|
249
|
-
class: `${ns.e("sign")} is-${tone}`,
|
|
250
|
-
title
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
return out;
|
|
254
|
-
}
|
|
255
|
-
}],
|
|
256
424
|
widgets() {
|
|
257
425
|
const out = [];
|
|
426
|
+
const fills = splitPlan.value[side].fills;
|
|
258
427
|
hunks.value.forEach((hunk, i) => {
|
|
259
428
|
const missing = otherCountOf(hunk) - countOf(hunk);
|
|
260
429
|
if (missing <= 0) return;
|
|
261
430
|
const last = startOf(hunk) - 1 + countOf(hunk);
|
|
431
|
+
const blanks = fills.get(i) ?? [];
|
|
262
432
|
out.push({
|
|
263
|
-
id: `fill-${i}`,
|
|
433
|
+
id: `fill-${i}-${missing}-${blanks.map((blank) => blank.height).join(".")}`,
|
|
264
434
|
...last >= 1 ? { line: last } : {
|
|
265
435
|
line: 1,
|
|
266
436
|
position: "above"
|
|
267
437
|
},
|
|
268
|
-
height: missing *
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` }
|
|
272
|
-
})
|
|
438
|
+
height: missing * LINE + blanks.reduce((sum, blank) => sum + blank.height, 0),
|
|
439
|
+
fullWidth: true,
|
|
440
|
+
render: () => filler(missing, blanks)
|
|
273
441
|
});
|
|
274
442
|
});
|
|
275
443
|
const total = side === "a" ? originalLines.value.length : modifiedLines.value.length;
|
|
@@ -284,6 +452,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
284
452
|
position: "above"
|
|
285
453
|
} : { line: first - 1 },
|
|
286
454
|
height: BAR_HEIGHT,
|
|
455
|
+
fullWidth: true,
|
|
287
456
|
render: () => bar(run, side === "a")
|
|
288
457
|
});
|
|
289
458
|
}
|
|
@@ -303,21 +472,87 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
303
472
|
}
|
|
304
473
|
});
|
|
305
474
|
}
|
|
475
|
+
/** Rows of filler, or rows split by the blanks of widgets on the other side. */
|
|
476
|
+
const block = (count) => h("div", {
|
|
477
|
+
class: ns.e("filler"),
|
|
478
|
+
style: { height: `calc(${count} * var(--dou-code-editor-line-height))` }
|
|
479
|
+
});
|
|
480
|
+
function filler(rows, blanks) {
|
|
481
|
+
if (!blanks.length) return block(rows);
|
|
482
|
+
const children = [];
|
|
483
|
+
let at = 0;
|
|
484
|
+
for (const blank of [...blanks].sort((x, y) => x.offset - y.offset || +x.above - +y.above)) {
|
|
485
|
+
if (blank.offset > at) children.push(block(blank.offset - at));
|
|
486
|
+
children.push(spacer(blank.height, blank.span)());
|
|
487
|
+
at = Math.max(at, blank.offset);
|
|
488
|
+
}
|
|
489
|
+
if (rows > at) children.push(block(rows - at));
|
|
490
|
+
return h("div", children);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* The `+`/`−` column of one side. It goes after every other extension, so it
|
|
494
|
+
* is always the gutter's last column, next to the text: its tint spreads
|
|
495
|
+
* over the whole gutter row from there (see style.css).
|
|
496
|
+
*/
|
|
497
|
+
function signExtension(side) {
|
|
498
|
+
const startOf = (hunk) => side === "a" ? hunk.originalStart : hunk.modifiedStart;
|
|
499
|
+
const countOf = (hunk) => side === "a" ? hunk.originalCount : hunk.modifiedCount;
|
|
500
|
+
const tone = side === "a" ? "removed" : "added";
|
|
501
|
+
return defineCodeExtension({
|
|
502
|
+
name: "diff-sign",
|
|
503
|
+
gutters: [{
|
|
504
|
+
name: "diff",
|
|
505
|
+
width: 16,
|
|
506
|
+
markers({ visible }) {
|
|
507
|
+
const out = [];
|
|
508
|
+
const title = side === "a" ? messages.value.diffRemoved : messages.value.diffAdded;
|
|
509
|
+
for (const hunk of hunks.value) {
|
|
510
|
+
const start = startOf(hunk);
|
|
511
|
+
const count = countOf(hunk);
|
|
512
|
+
if (start > visible.to) break;
|
|
513
|
+
for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++) out.push({
|
|
514
|
+
line: n,
|
|
515
|
+
text: side === "a" ? "−" : "+",
|
|
516
|
+
class: `${ns.e("sign")} is-${tone}`,
|
|
517
|
+
title
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
return out;
|
|
521
|
+
}
|
|
522
|
+
}]
|
|
523
|
+
});
|
|
524
|
+
}
|
|
306
525
|
const modifiedOwn = sideExtension("b");
|
|
307
|
-
const
|
|
526
|
+
const signB = signExtension("b");
|
|
527
|
+
const modifiedExtensions = computed(() => [
|
|
528
|
+
annotationsB,
|
|
529
|
+
modifiedOwn,
|
|
530
|
+
annotationsEndB,
|
|
531
|
+
...props.extensions ?? [],
|
|
532
|
+
signB
|
|
533
|
+
]);
|
|
308
534
|
const editorA = ref();
|
|
309
535
|
const editorB = ref();
|
|
310
536
|
const sideA = ref();
|
|
311
537
|
const sideB = ref();
|
|
312
|
-
const extensionsA = [
|
|
313
|
-
|
|
538
|
+
const extensionsA = [
|
|
539
|
+
annotations("a"),
|
|
540
|
+
sideExtension("a"),
|
|
541
|
+
annotations("a", true),
|
|
542
|
+
signExtension("a")
|
|
543
|
+
];
|
|
544
|
+
const annotationsB = annotations("b");
|
|
545
|
+
const annotationsEndB = annotations("b", true);
|
|
546
|
+
const linkXY = createScrollLink("xy");
|
|
547
|
+
const linkX = createScrollLink("x");
|
|
314
548
|
function onScroll(event) {
|
|
315
549
|
if (view.value !== "split") return;
|
|
550
|
+
if (spans.value.length) schedulePlace();
|
|
316
551
|
const from = event.target.closest(`.${ns.e("side")}`);
|
|
317
552
|
const source = from?.querySelector(".dou-code-editor__scroller");
|
|
318
553
|
if (!source || source !== event.target) return;
|
|
319
554
|
const other = (from === sideA.value ? sideB.value : sideA.value)?.querySelector(".dou-code-editor__scroller");
|
|
320
|
-
if (other)
|
|
555
|
+
if (other) (props.scrollY ? linkXY : linkX).follow(source, other);
|
|
321
556
|
}
|
|
322
557
|
const unified = computed(() => {
|
|
323
558
|
if (view.value !== "inline") return null;
|
|
@@ -330,12 +565,16 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
330
565
|
const hunkLines = [];
|
|
331
566
|
const runLines = /* @__PURE__ */ new Map();
|
|
332
567
|
const marks = [];
|
|
568
|
+
const aRows = new Int32Array(a.length + 1);
|
|
569
|
+
const bRows = new Int32Array(b.length + 1);
|
|
333
570
|
let pos = 0;
|
|
334
571
|
const push = (text, kind, an, bn) => {
|
|
335
572
|
lines.push(text);
|
|
336
573
|
kinds.push(kind);
|
|
337
574
|
aNums.push(an);
|
|
338
575
|
bNums.push(bn);
|
|
576
|
+
if (an) aRows[an] = lines.length;
|
|
577
|
+
if (bn) bRows[bn] = lines.length;
|
|
339
578
|
pos += text.length + 1;
|
|
340
579
|
};
|
|
341
580
|
const runs = unchanged.value;
|
|
@@ -377,15 +616,21 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
377
616
|
kinds: Uint8Array.from(kinds),
|
|
378
617
|
aNums: Int32Array.from(aNums),
|
|
379
618
|
bNums: Int32Array.from(bNums),
|
|
619
|
+
aRows,
|
|
620
|
+
bRows,
|
|
380
621
|
hunkLines,
|
|
381
622
|
runLines,
|
|
382
623
|
marks
|
|
383
624
|
};
|
|
384
625
|
});
|
|
385
626
|
const digits = (n) => String(Math.max(1, n)).length;
|
|
386
|
-
|
|
627
|
+
function numberWidth(n, side) {
|
|
628
|
+
const count = digits(n);
|
|
629
|
+
if (compact.value) return count * 7 + (side === "original" ? 8 : 6);
|
|
630
|
+
return Math.ceil(count * 7.5) + (side === "original" ? 12 : 8);
|
|
631
|
+
}
|
|
387
632
|
/** The line numbers of one side, in the inline view's gutter. */
|
|
388
|
-
const numbersOf = (pick) => ({ visible }) => {
|
|
633
|
+
const numbersOf = (pick, side) => ({ visible }) => {
|
|
389
634
|
const u = unified.value;
|
|
390
635
|
if (!u) return [];
|
|
391
636
|
const out = [];
|
|
@@ -397,12 +642,12 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
397
642
|
out.push({
|
|
398
643
|
line: n,
|
|
399
644
|
text: value ? String(value) : "",
|
|
400
|
-
class: `${ns.e("number")}${tone}`
|
|
645
|
+
class: `${ns.e("number")} is-${side}${tone}`
|
|
401
646
|
});
|
|
402
647
|
}
|
|
403
648
|
return out;
|
|
404
649
|
};
|
|
405
|
-
const
|
|
650
|
+
const inlineExtension = defineCodeExtension({
|
|
406
651
|
name: "diff",
|
|
407
652
|
decorations({ visible }) {
|
|
408
653
|
const u = unified.value;
|
|
@@ -433,17 +678,17 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
433
678
|
return [
|
|
434
679
|
{
|
|
435
680
|
name: "diff-original",
|
|
436
|
-
width: numberWidth(originalLines.value.length),
|
|
437
|
-
markers: numbersOf("aNums")
|
|
681
|
+
width: numberWidth(originalLines.value.length, "original"),
|
|
682
|
+
markers: numbersOf("aNums", "original")
|
|
438
683
|
},
|
|
439
684
|
{
|
|
440
685
|
name: "diff-modified",
|
|
441
|
-
width: numberWidth(modifiedLines.value.length),
|
|
442
|
-
markers: numbersOf("bNums")
|
|
686
|
+
width: numberWidth(modifiedLines.value.length, "modified"),
|
|
687
|
+
markers: numbersOf("bNums", "modified")
|
|
443
688
|
},
|
|
444
689
|
{
|
|
445
690
|
name: "diff",
|
|
446
|
-
width: 16,
|
|
691
|
+
width: compact.value ? 14 : 16,
|
|
447
692
|
markers: ({ visible }) => {
|
|
448
693
|
const u = unified.value;
|
|
449
694
|
if (!u) return [];
|
|
@@ -484,6 +729,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
484
729
|
position: "above"
|
|
485
730
|
} : { line: first - 1 },
|
|
486
731
|
height: BAR_HEIGHT,
|
|
732
|
+
fullWidth: true,
|
|
487
733
|
render: () => bar(run)
|
|
488
734
|
});
|
|
489
735
|
}
|
|
@@ -503,9 +749,399 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
503
749
|
}
|
|
504
750
|
return out;
|
|
505
751
|
}
|
|
506
|
-
})
|
|
752
|
+
});
|
|
753
|
+
const inlineExtensions = [
|
|
754
|
+
inlineAnnotations(),
|
|
755
|
+
inlineExtension,
|
|
756
|
+
inlineAnnotations(true)
|
|
757
|
+
];
|
|
507
758
|
const editorInline = ref();
|
|
508
759
|
const inlineBox = ref();
|
|
760
|
+
/** One line's height, before the editors have measured theirs. */
|
|
761
|
+
const sideName = (side) => side === "a" ? "original" : "modified";
|
|
762
|
+
/** The widgets' measured heights, by id, for the blank left beside each. */
|
|
763
|
+
const heights = reactive(/* @__PURE__ */ new Map());
|
|
764
|
+
let heightObserver;
|
|
765
|
+
/** The element each widget's content is drawn in now, by id, and back. */
|
|
766
|
+
const measuredEls = /* @__PURE__ */ new Map();
|
|
767
|
+
const measuredIds = /* @__PURE__ */ new Map();
|
|
768
|
+
function readHeight(box, entry) {
|
|
769
|
+
const id = measuredIds.get(box);
|
|
770
|
+
const size = entry?.borderBoxSize?.[0]?.blockSize ?? entry?.contentRect.height;
|
|
771
|
+
const height = size === void 0 ? box.offsetHeight : Math.round(size);
|
|
772
|
+
if (id && height && heights.get(id) !== height) heights.set(id, height);
|
|
773
|
+
}
|
|
774
|
+
function forget(box) {
|
|
775
|
+
heightObserver?.unobserve(box);
|
|
776
|
+
measuredIds.delete(box);
|
|
777
|
+
}
|
|
778
|
+
/** Measures a widget across both sides as drawn, now and whenever it resizes; `null` once it is gone. */
|
|
779
|
+
function measure(el, id) {
|
|
780
|
+
const had = measuredEls.get(id);
|
|
781
|
+
if (!el) {
|
|
782
|
+
if (had && !had.isConnected) {
|
|
783
|
+
forget(had);
|
|
784
|
+
measuredEls.delete(id);
|
|
785
|
+
}
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (had === el) return;
|
|
789
|
+
if (had) forget(had);
|
|
790
|
+
measuredEls.set(id, el);
|
|
791
|
+
measuredIds.set(el, id);
|
|
792
|
+
readHeight(el);
|
|
793
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
794
|
+
heightObserver ??= new ResizeObserver((entries) => {
|
|
795
|
+
for (const entry of entries) readHeight(entry.target, entry);
|
|
796
|
+
});
|
|
797
|
+
heightObserver.observe(el);
|
|
798
|
+
}
|
|
799
|
+
onBeforeUnmount(() => heightObserver?.disconnect());
|
|
800
|
+
const heightOf = (widget) => heights.get(widget.id) ?? widget.height ?? LINE;
|
|
801
|
+
const widgetIds = computed(() => new Set((props.widgets ?? []).map((widget) => widget.id)));
|
|
802
|
+
provide(WIDGET_HEIGHT_KEY, (key, height) => {
|
|
803
|
+
if (!key.startsWith("diff-widgets")) return;
|
|
804
|
+
const id = key.slice(key.indexOf("/") + 1);
|
|
805
|
+
if (widgetIds.value.has(id) && heights.get(id) !== height) heights.set(id, height);
|
|
806
|
+
});
|
|
807
|
+
/** A widget's own content. */
|
|
808
|
+
const content = (widget) => () => h("div", { class: ns.e("widget") }, [widget.render()]);
|
|
809
|
+
/** The blank across from a widget; `span` marks where a widget across both sides is drawn. */
|
|
810
|
+
const spacer = (height, span) => () => h("div", {
|
|
811
|
+
class: ns.e("spacer"),
|
|
812
|
+
style: { height: `${height}px` },
|
|
813
|
+
"data-diff-span": span
|
|
814
|
+
});
|
|
815
|
+
/** A blank inside a filler: `offset` rows into it. */
|
|
816
|
+
function across(side, line, above) {
|
|
817
|
+
const list = hunks.value;
|
|
818
|
+
for (let i = 0; i < list.length; i++) {
|
|
819
|
+
const hunk = list[i];
|
|
820
|
+
const start = side === "a" ? hunk.originalStart : hunk.modifiedStart;
|
|
821
|
+
const count = side === "a" ? hunk.originalCount : hunk.modifiedCount;
|
|
822
|
+
if (line < start) break;
|
|
823
|
+
if (line >= start + count) continue;
|
|
824
|
+
const otherStart = side === "a" ? hunk.modifiedStart : hunk.originalStart;
|
|
825
|
+
const otherCount = side === "a" ? hunk.modifiedCount : hunk.originalCount;
|
|
826
|
+
const index = line - start;
|
|
827
|
+
if (index < otherCount) return { line: otherStart + index };
|
|
828
|
+
return {
|
|
829
|
+
fill: i,
|
|
830
|
+
offset: index - otherCount + (above ? 0 : 1)
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
for (const run of unchanged.value) {
|
|
834
|
+
const start = side === "a" ? run.a : run.b;
|
|
835
|
+
if (line >= start && line < start + run.count) return { line: line - start + (side === "a" ? run.b : run.a) };
|
|
836
|
+
}
|
|
837
|
+
return null;
|
|
838
|
+
}
|
|
839
|
+
/** Side by side: each widget on its side, a blank of its height on the other. */
|
|
840
|
+
if (process.env.NODE_ENV !== "production") {
|
|
841
|
+
const warned = /* @__PURE__ */ new Set();
|
|
842
|
+
watch(() => props.widgets, (widgets) => {
|
|
843
|
+
const seen = /* @__PURE__ */ new Set();
|
|
844
|
+
for (const widget of widgets ?? []) {
|
|
845
|
+
if (seen.has(widget.id) && !warned.has(widget.id)) {
|
|
846
|
+
warned.add(widget.id);
|
|
847
|
+
console.warn(`[@dou-ui/code] DouCodeDiff: widget id "${widget.id}" is used more than once; ids must be unique across both sides.`);
|
|
848
|
+
}
|
|
849
|
+
seen.add(widget.id);
|
|
850
|
+
}
|
|
851
|
+
}, { immediate: true });
|
|
852
|
+
}
|
|
853
|
+
const splitPlan = computed(() => {
|
|
854
|
+
const plan = {
|
|
855
|
+
a: {
|
|
856
|
+
below: [],
|
|
857
|
+
above: [],
|
|
858
|
+
fills: /* @__PURE__ */ new Map()
|
|
859
|
+
},
|
|
860
|
+
b: {
|
|
861
|
+
below: [],
|
|
862
|
+
above: [],
|
|
863
|
+
fills: /* @__PURE__ */ new Map()
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
if (view.value !== "split") return plan;
|
|
867
|
+
for (const widget of props.widgets ?? []) {
|
|
868
|
+
const own = widget.side === "original" ? "a" : "b";
|
|
869
|
+
const other = own === "a" ? "b" : "a";
|
|
870
|
+
const lines = own === "a" ? originalLines.value.length : modifiedLines.value.length;
|
|
871
|
+
if (!(widget.line >= 1 && widget.line <= lines)) continue;
|
|
872
|
+
const above = widget.position === "above";
|
|
873
|
+
const height = heightOf(widget);
|
|
874
|
+
const span = widget.span === "both" ? widget.id : void 0;
|
|
875
|
+
const put = (side, line, render, label, blank = false) => plan[side][above ? "above" : "below"].push({
|
|
876
|
+
id: blank ? `${widget.id}~${height}` : widget.id,
|
|
877
|
+
line,
|
|
878
|
+
position: above ? "above" : "below",
|
|
879
|
+
height,
|
|
880
|
+
label,
|
|
881
|
+
render
|
|
882
|
+
});
|
|
883
|
+
if (span) put(own, widget.line, spacer(height, span), widget.label, true);
|
|
884
|
+
else put(own, widget.line, content(widget), widget.label);
|
|
885
|
+
const spot = across(own, widget.line, above);
|
|
886
|
+
if (!spot) continue;
|
|
887
|
+
if ("fill" in spot) {
|
|
888
|
+
const fills = plan[other].fills;
|
|
889
|
+
const blanks = fills.get(spot.fill) ?? [];
|
|
890
|
+
blanks.push({
|
|
891
|
+
offset: spot.offset,
|
|
892
|
+
above,
|
|
893
|
+
height,
|
|
894
|
+
span
|
|
895
|
+
});
|
|
896
|
+
fills.set(spot.fill, blanks);
|
|
897
|
+
} else put(other, spot.line, spacer(height, span), void 0, true);
|
|
898
|
+
}
|
|
899
|
+
return plan;
|
|
900
|
+
});
|
|
901
|
+
/** The widgets drawn across both sides, over them. */
|
|
902
|
+
const spans = computed(() => view.value === "split" ? (props.widgets ?? []).filter((widget) => widget.span === "both") : []);
|
|
903
|
+
/** Whether a column's `hoverMarker` goes on the lines of `side`. */
|
|
904
|
+
function hoversOn(gutter, side) {
|
|
905
|
+
return !!gutter.hoverMarker && (!gutter.hoverMarker.side || gutter.hoverMarker.side === side);
|
|
906
|
+
}
|
|
907
|
+
/** Whether a column has a marker of its own on line `line` of `side`. */
|
|
908
|
+
function ownMarkerOn(gutter, side, line) {
|
|
909
|
+
return line > 0 && (gutter.markers ?? []).some((m) => m.side === side && m.line === line);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Which line of which side a press on a column goes to, or `null` for none.
|
|
913
|
+
* A column whose `hoverMarker` is on one side only answers presses on the
|
|
914
|
+
* other side's own markers, not on its empty cells.
|
|
915
|
+
*/
|
|
916
|
+
function pressedOn(gutter, side, line) {
|
|
917
|
+
if (!gutter.hoverMarker || hoversOn(gutter, side) || ownMarkerOn(gutter, side, line)) return side;
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
/** The column's `hoverMarker` as the editor of one side takes it, named for that side. */
|
|
921
|
+
function hoverMarkerOf(hover, side) {
|
|
922
|
+
const { title } = hover;
|
|
923
|
+
return {
|
|
924
|
+
icon: hover.icon,
|
|
925
|
+
text: hover.text,
|
|
926
|
+
class: hover.class,
|
|
927
|
+
title: typeof title === "function" ? (line) => title(line, side) : title
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/** Whether a gutter column floats over the gutter edge instead of reserving width. */
|
|
931
|
+
function isOverlay(gutter) {
|
|
932
|
+
return gutter.overlay === true || gutter.overlay === "compact" && compact.value;
|
|
933
|
+
}
|
|
934
|
+
/** A column of `gutters` as one side's editor draws it. */
|
|
935
|
+
function sideGutter(gutter, side) {
|
|
936
|
+
const name = sideName(side);
|
|
937
|
+
return {
|
|
938
|
+
name: gutter.name,
|
|
939
|
+
width: gutter.width,
|
|
940
|
+
overlay: isOverlay(gutter),
|
|
941
|
+
markers: ({ visible }) => (gutter.markers ?? []).filter((marker) => marker.side === name && marker.line >= visible.from && marker.line <= visible.to),
|
|
942
|
+
hoverMarker: hoversOn(gutter, name) ? hoverMarkerOf(gutter.hoverMarker, name) : void 0,
|
|
943
|
+
pressOn: gutter.hoverMarker?.side ? "markers" : gutter.pressOn,
|
|
944
|
+
onPress: gutter.onPress && ((line, event) => {
|
|
945
|
+
if (pressedOn(gutter, name, line)) gutter.onPress(line, event, name);
|
|
946
|
+
})
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* The `gutters` and `widgets` of one side. Two of them go around the
|
|
951
|
+
* diff's own: widgets below a line come before its filler or bar, those
|
|
952
|
+
* above a line after them.
|
|
953
|
+
*/
|
|
954
|
+
function annotations(side, end = false) {
|
|
955
|
+
return defineCodeExtension({
|
|
956
|
+
name: end ? "diff-widgets-end" : "diff-widgets",
|
|
957
|
+
get gutters() {
|
|
958
|
+
return end ? [] : (props.gutters ?? []).map((gutter) => sideGutter(gutter, side));
|
|
959
|
+
},
|
|
960
|
+
widgets: () => splitPlan.value[side][end ? "above" : "below"]
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
/** Where line `line` of `side` is inline, from 1; 0 when it isn't there. */
|
|
964
|
+
function inlineRow(u, side, line) {
|
|
965
|
+
const rows = side === "original" ? u.aRows : u.bRows;
|
|
966
|
+
return line >= 1 && line < rows.length ? rows[line] : 0;
|
|
967
|
+
}
|
|
968
|
+
/** The `gutters` and `widgets` inline, on the rows of their lines. */
|
|
969
|
+
function inlineAnnotations(end = false) {
|
|
970
|
+
return defineCodeExtension({
|
|
971
|
+
name: end ? "diff-widgets-end" : "diff-widgets",
|
|
972
|
+
get gutters() {
|
|
973
|
+
if (end) return [];
|
|
974
|
+
return (props.gutters ?? []).map((gutter) => ({
|
|
975
|
+
name: gutter.name,
|
|
976
|
+
width: gutter.width,
|
|
977
|
+
overlay: isOverlay(gutter),
|
|
978
|
+
pressOn: gutter.hoverMarker?.side ? "markers" : gutter.pressOn,
|
|
979
|
+
markers: ({ visible }) => {
|
|
980
|
+
const u = unified.value;
|
|
981
|
+
if (!u) return [];
|
|
982
|
+
const out = [];
|
|
983
|
+
const taken = /* @__PURE__ */ new Set();
|
|
984
|
+
for (const side of ["modified", "original"]) for (const marker of gutter.markers ?? []) {
|
|
985
|
+
if (marker.side !== side) continue;
|
|
986
|
+
const row = inlineRow(u, side, marker.line);
|
|
987
|
+
if (!row || row < visible.from || row > visible.to || taken.has(row)) continue;
|
|
988
|
+
out.push({
|
|
989
|
+
...marker,
|
|
990
|
+
line: row
|
|
991
|
+
});
|
|
992
|
+
taken.add(row);
|
|
993
|
+
}
|
|
994
|
+
if (gutter.hoverMarker) for (let row = visible.from; row <= visible.to && row <= u.kinds.length; row++) {
|
|
995
|
+
if (taken.has(row)) continue;
|
|
996
|
+
const b = u.bNums[row - 1] ?? 0;
|
|
997
|
+
const a = u.aNums[row - 1] ?? 0;
|
|
998
|
+
const at = b && hoversOn(gutter, "modified") ? [b, "modified"] : a && hoversOn(gutter, "original") ? [a, "original"] : null;
|
|
999
|
+
if (!at) continue;
|
|
1000
|
+
const { icon, text, class: className, title } = gutter.hoverMarker;
|
|
1001
|
+
out.push({
|
|
1002
|
+
icon,
|
|
1003
|
+
text,
|
|
1004
|
+
class: className,
|
|
1005
|
+
title: typeof title === "function" ? title(at[0], at[1]) : title,
|
|
1006
|
+
line: row,
|
|
1007
|
+
visible: "hover"
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return out;
|
|
1011
|
+
},
|
|
1012
|
+
onPress: gutter.onPress && ((row, event) => {
|
|
1013
|
+
const u = unified.value;
|
|
1014
|
+
if (!u) return;
|
|
1015
|
+
const a = u.aNums[row - 1] ?? 0;
|
|
1016
|
+
const b = u.bNums[row - 1] ?? 0;
|
|
1017
|
+
const press = (side, line) => gutter.onPress(line, event, side);
|
|
1018
|
+
if (ownMarkerOn(gutter, "modified", b)) return press("modified", b);
|
|
1019
|
+
if (ownMarkerOn(gutter, "original", a)) return press("original", a);
|
|
1020
|
+
if (!gutter.hoverMarker) return b ? press("modified", b) : press("original", a);
|
|
1021
|
+
if (b && hoversOn(gutter, "modified")) press("modified", b);
|
|
1022
|
+
else if (a && hoversOn(gutter, "original")) press("original", a);
|
|
1023
|
+
})
|
|
1024
|
+
}));
|
|
1025
|
+
},
|
|
1026
|
+
widgets() {
|
|
1027
|
+
const u = unified.value;
|
|
1028
|
+
if (!u) return [];
|
|
1029
|
+
const out = [];
|
|
1030
|
+
for (const widget of props.widgets ?? []) {
|
|
1031
|
+
if (widget.position === "above" !== end) continue;
|
|
1032
|
+
const row = inlineRow(u, widget.side, widget.line);
|
|
1033
|
+
if (!row) continue;
|
|
1034
|
+
out.push({
|
|
1035
|
+
id: widget.id,
|
|
1036
|
+
line: row,
|
|
1037
|
+
position: widget.position,
|
|
1038
|
+
height: heightOf(widget),
|
|
1039
|
+
label: widget.label,
|
|
1040
|
+
render: content(widget)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return out;
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
const spanLayer = ref();
|
|
1048
|
+
/** Where the layer of widgets across both sides is: over the text of the sides. */
|
|
1049
|
+
const spanBox = ref({
|
|
1050
|
+
top: 0,
|
|
1051
|
+
height: 0
|
|
1052
|
+
});
|
|
1053
|
+
/** Each widget's y in the layer, by id; left out while its blank isn't drawn. */
|
|
1054
|
+
const spanTops = ref({});
|
|
1055
|
+
let placeFrame = 0;
|
|
1056
|
+
function schedulePlace() {
|
|
1057
|
+
if (!placeFrame && typeof requestAnimationFrame !== "undefined") placeFrame = requestAnimationFrame(placeSpans);
|
|
1058
|
+
}
|
|
1059
|
+
/** Puts each widget across both sides over its blank. */
|
|
1060
|
+
function placeSpans() {
|
|
1061
|
+
placeFrame = 0;
|
|
1062
|
+
const body = spanLayer.value?.parentElement;
|
|
1063
|
+
const scroller = sideA.value?.querySelector(".dou-code-editor__scroller");
|
|
1064
|
+
if (!body || !scroller) return;
|
|
1065
|
+
const frame = scroller.getBoundingClientRect();
|
|
1066
|
+
const top = frame.top - body.getBoundingClientRect().top;
|
|
1067
|
+
if (spanBox.value.top !== top || spanBox.value.height !== frame.height) spanBox.value = {
|
|
1068
|
+
top,
|
|
1069
|
+
height: frame.height
|
|
1070
|
+
};
|
|
1071
|
+
const tops = {};
|
|
1072
|
+
for (const box of [sideA.value, sideB.value]) for (const el of box?.querySelectorAll("[data-diff-span]") ?? []) {
|
|
1073
|
+
const id = el.dataset.diffSpan;
|
|
1074
|
+
if (!(id in tops)) tops[id] = el.getBoundingClientRect().top - frame.top;
|
|
1075
|
+
}
|
|
1076
|
+
const had = spanTops.value;
|
|
1077
|
+
const keys = Object.keys(tops);
|
|
1078
|
+
if (keys.length !== Object.keys(had).length || keys.some((id) => had[id] !== tops[id])) spanTops.value = tops;
|
|
1079
|
+
}
|
|
1080
|
+
const sideScrollTop = /* @__PURE__ */ new WeakMap();
|
|
1081
|
+
let stopPlacing;
|
|
1082
|
+
function startPlacing() {
|
|
1083
|
+
stopPlacing?.();
|
|
1084
|
+
stopPlacing = void 0;
|
|
1085
|
+
if (!spans.value.length || !sideA.value) return;
|
|
1086
|
+
for (const side of [sideA.value, sideB.value]) {
|
|
1087
|
+
const scroller = side?.querySelector(".dou-code-editor__scroller");
|
|
1088
|
+
if (scroller) sideScrollTop.set(scroller, scroller.scrollTop);
|
|
1089
|
+
}
|
|
1090
|
+
placeSpans();
|
|
1091
|
+
const moved = typeof MutationObserver === "undefined" ? null : new MutationObserver(schedulePlace);
|
|
1092
|
+
for (const side of [sideA.value, sideB.value]) if (side) moved?.observe(side, {
|
|
1093
|
+
subtree: true,
|
|
1094
|
+
childList: true,
|
|
1095
|
+
attributeFilter: ["style"]
|
|
1096
|
+
});
|
|
1097
|
+
const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedulePlace);
|
|
1098
|
+
if (root.value) resized?.observe(root.value);
|
|
1099
|
+
stopPlacing = () => {
|
|
1100
|
+
moved?.disconnect();
|
|
1101
|
+
resized?.disconnect();
|
|
1102
|
+
if (placeFrame) cancelAnimationFrame(placeFrame);
|
|
1103
|
+
placeFrame = 0;
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
watch(() => spans.value.length > 0 && view.value, startPlacing, { flush: "post" });
|
|
1107
|
+
onMounted(startPlacing);
|
|
1108
|
+
onBeforeUnmount(() => stopPlacing?.());
|
|
1109
|
+
/**
|
|
1110
|
+
* While the text scrolls, the widgets across both sides are hidden: placed a
|
|
1111
|
+
* frame late, they would trail behind it. They come back once it rests.
|
|
1112
|
+
*/
|
|
1113
|
+
const spansScrolling = ref(false);
|
|
1114
|
+
let restTimer;
|
|
1115
|
+
function onSideScroll(event) {
|
|
1116
|
+
const scroller = event.target;
|
|
1117
|
+
if (!scroller?.classList.contains("dou-code-editor__scroller")) return;
|
|
1118
|
+
const top = scroller.scrollTop;
|
|
1119
|
+
const prev = sideScrollTop.get(scroller);
|
|
1120
|
+
sideScrollTop.set(scroller, top);
|
|
1121
|
+
if (!spans.value.length) return;
|
|
1122
|
+
if (prev !== void 0 ? prev === top : top === 0) return;
|
|
1123
|
+
spansScrolling.value = true;
|
|
1124
|
+
clearTimeout(restTimer);
|
|
1125
|
+
restTimer = setTimeout(() => {
|
|
1126
|
+
spansScrolling.value = false;
|
|
1127
|
+
placeSpans();
|
|
1128
|
+
}, 120);
|
|
1129
|
+
}
|
|
1130
|
+
onBeforeUnmount(() => clearTimeout(restTimer));
|
|
1131
|
+
/** A wheel over a widget across both sides scrolls the text under it. */
|
|
1132
|
+
function onSpanWheel(event) {
|
|
1133
|
+
const scroller = sideB.value?.querySelector(".dou-code-editor__scroller");
|
|
1134
|
+
if (!scroller) return;
|
|
1135
|
+
const unit = event.deltaMode === 1 ? LINE : event.deltaMode === 2 ? scroller.clientHeight : 1;
|
|
1136
|
+
const dy = event.deltaY * unit;
|
|
1137
|
+
const dx = event.deltaX * unit;
|
|
1138
|
+
const canY = props.scrollY && (dy < 0 ? scroller.scrollTop > 0 : dy > 0 && scroller.scrollTop + scroller.clientHeight < scroller.scrollHeight - 1);
|
|
1139
|
+
const canX = dx < 0 ? scroller.scrollLeft > 0 : dx > 0 && scroller.scrollLeft + scroller.clientWidth < scroller.scrollWidth - 1;
|
|
1140
|
+
if (!canY && !canX) return;
|
|
1141
|
+
event.preventDefault();
|
|
1142
|
+
if (canY) scroller.scrollTop += dy;
|
|
1143
|
+
if (canX) scroller.scrollLeft += dx;
|
|
1144
|
+
}
|
|
509
1145
|
/** Shows the run of hidden lines a cursor moved into, e.g. with search. */
|
|
510
1146
|
function revealAt(side, result) {
|
|
511
1147
|
if (!hiddenCount.value) return;
|
|
@@ -589,12 +1225,22 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
589
1225
|
get hunks() {
|
|
590
1226
|
return hunks.value;
|
|
591
1227
|
},
|
|
1228
|
+
/** Whether any run of unchanged lines can be collapsed under the current settings. */
|
|
1229
|
+
get anyHideable() {
|
|
1230
|
+
return anyHideable.value;
|
|
1231
|
+
},
|
|
1232
|
+
/** How many unchanged lines are currently hidden behind collapse bars. */
|
|
1233
|
+
get hiddenCount() {
|
|
1234
|
+
return hiddenCount.value;
|
|
1235
|
+
},
|
|
592
1236
|
/** Moves to the next change; `false` when there is none. */
|
|
593
1237
|
next,
|
|
594
1238
|
/** Moves to the previous change. */
|
|
595
1239
|
previous,
|
|
596
1240
|
/** Shows every unchanged line. */
|
|
597
|
-
expandAll: () =>
|
|
1241
|
+
expandAll: () => {
|
|
1242
|
+
allOpen.value = true;
|
|
1243
|
+
},
|
|
598
1244
|
/** Hides the runs of unchanged lines again. */
|
|
599
1245
|
collapseAll: () => {
|
|
600
1246
|
allOpen.value = false;
|
|
@@ -615,15 +1261,21 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
615
1261
|
class: normalizeClass([
|
|
616
1262
|
unref(ns).b(),
|
|
617
1263
|
unref(ns).m(view.value),
|
|
618
|
-
unref(ns).is("
|
|
1264
|
+
unref(ns).is("compact", compact.value),
|
|
1265
|
+
unref(ns).is("bordered", __props.bordered),
|
|
1266
|
+
unref(ns).is("scroll-y", __props.scrollY)
|
|
619
1267
|
]),
|
|
620
1268
|
role: "group",
|
|
621
1269
|
"aria-label": unref(messages).diff
|
|
622
1270
|
}, [
|
|
623
1271
|
__props.toolbar ? (openBlock(), createElementBlock("div", {
|
|
624
1272
|
key: 0,
|
|
625
|
-
class: normalizeClass(unref(ns).e("toolbar"))
|
|
1273
|
+
class: normalizeClass([unref(ns).e("toolbar"), unref(ns).is("sticky", __props.stickyToolbar)])
|
|
626
1274
|
}, [
|
|
1275
|
+
slots.title ? (openBlock(), createElementBlock("div", {
|
|
1276
|
+
key: 0,
|
|
1277
|
+
class: normalizeClass(unref(ns).e("title"))
|
|
1278
|
+
}, [renderSlot(_ctx.$slots, "title")], 2)) : createCommentVNode("", true),
|
|
627
1279
|
createElementVNode("span", { class: normalizeClass(unref(ns).e("stats")) }, [hunks.value.length ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
628
1280
|
createElementVNode("span", {
|
|
629
1281
|
class: normalizeClass([unref(ns).e("count"), "is-added"]),
|
|
@@ -671,7 +1323,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
671
1323
|
_: 1
|
|
672
1324
|
}, 8, ["content"]),
|
|
673
1325
|
anyHideable.value ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
674
|
-
key:
|
|
1326
|
+
key: 1,
|
|
675
1327
|
content: hiddenCount.value ? unref(messages).diffExpandAll : unref(messages).diffCollapse
|
|
676
1328
|
}, {
|
|
677
1329
|
default: withCtx(() => [createVNode(unref(DouButton), {
|
|
@@ -708,12 +1360,15 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
708
1360
|
createElementVNode("div", {
|
|
709
1361
|
ref_key: "sideA",
|
|
710
1362
|
ref: sideA,
|
|
1363
|
+
onScrollCapturePassive: onSideScroll,
|
|
711
1364
|
class: normalizeClass([unref(ns).e("side"), "is-original"])
|
|
712
1365
|
}, [createVNode(code_editor_default, {
|
|
713
1366
|
ref_key: "editorA",
|
|
714
1367
|
ref: editorA,
|
|
715
1368
|
"model-value": __props.original,
|
|
716
1369
|
language: __props.language,
|
|
1370
|
+
worker: __props.worker,
|
|
1371
|
+
"sync-highlight-lines": __props.syncHighlightLines,
|
|
717
1372
|
extensions: extensionsA,
|
|
718
1373
|
"tab-size": __props.tabSize,
|
|
719
1374
|
messages: unref(messages),
|
|
@@ -722,24 +1377,31 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
722
1377
|
foldable: false,
|
|
723
1378
|
"active-line": false,
|
|
724
1379
|
bordered: false,
|
|
1380
|
+
"scroll-y": __props.scrollY,
|
|
725
1381
|
readonly: "",
|
|
726
1382
|
onTransaction: _cache[0] || (_cache[0] = ($event) => revealAt("a", $event))
|
|
727
1383
|
}, null, 8, [
|
|
728
1384
|
"model-value",
|
|
729
1385
|
"language",
|
|
1386
|
+
"worker",
|
|
1387
|
+
"sync-highlight-lines",
|
|
730
1388
|
"tab-size",
|
|
731
1389
|
"messages",
|
|
732
|
-
"aria-label"
|
|
733
|
-
|
|
1390
|
+
"aria-label",
|
|
1391
|
+
"scroll-y"
|
|
1392
|
+
])], 34),
|
|
734
1393
|
createElementVNode("div", {
|
|
735
1394
|
ref_key: "sideB",
|
|
736
1395
|
ref: sideB,
|
|
1396
|
+
onScrollCapturePassive: onSideScroll,
|
|
737
1397
|
class: normalizeClass([unref(ns).e("side"), "is-modified"])
|
|
738
1398
|
}, [createVNode(code_editor_default, {
|
|
739
1399
|
ref_key: "editorB",
|
|
740
1400
|
ref: editorB,
|
|
741
1401
|
"model-value": modified.value,
|
|
742
1402
|
language: __props.language,
|
|
1403
|
+
worker: __props.worker,
|
|
1404
|
+
"sync-highlight-lines": __props.syncHighlightLines,
|
|
743
1405
|
extensions: modifiedExtensions.value,
|
|
744
1406
|
"tab-size": __props.tabSize,
|
|
745
1407
|
messages: unref(messages),
|
|
@@ -748,18 +1410,43 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
748
1410
|
foldable: false,
|
|
749
1411
|
"active-line": false,
|
|
750
1412
|
bordered: false,
|
|
1413
|
+
"scroll-y": __props.scrollY,
|
|
751
1414
|
readonly: !__props.editable,
|
|
752
1415
|
"onUpdate:modelValue": onModifiedInput,
|
|
753
1416
|
onTransaction: _cache[1] || (_cache[1] = ($event) => revealAt("b", $event))
|
|
754
1417
|
}, null, 8, [
|
|
755
1418
|
"model-value",
|
|
756
1419
|
"language",
|
|
1420
|
+
"worker",
|
|
1421
|
+
"sync-highlight-lines",
|
|
757
1422
|
"extensions",
|
|
758
1423
|
"tab-size",
|
|
759
1424
|
"messages",
|
|
760
1425
|
"aria-label",
|
|
1426
|
+
"scroll-y",
|
|
761
1427
|
"readonly"
|
|
762
|
-
])],
|
|
1428
|
+
])], 34),
|
|
1429
|
+
spans.value.length ? (openBlock(), createElementBlock("div", {
|
|
1430
|
+
key: 0,
|
|
1431
|
+
ref_key: "spanLayer",
|
|
1432
|
+
ref: spanLayer,
|
|
1433
|
+
class: normalizeClass(unref(ns).e("spans")),
|
|
1434
|
+
style: normalizeStyle({
|
|
1435
|
+
top: `${spanBox.value.top}px`,
|
|
1436
|
+
height: `${spanBox.value.height}px`
|
|
1437
|
+
})
|
|
1438
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(spans.value, (widget) => {
|
|
1439
|
+
return openBlock(), createElementBlock("div", {
|
|
1440
|
+
key: widget.id,
|
|
1441
|
+
ref_for: true,
|
|
1442
|
+
ref: (el) => measure(el, widget.id),
|
|
1443
|
+
class: normalizeClass([unref(ns).e("span"), unref(ns).is("placed", widget.id in spanTops.value && !spansScrolling.value)]),
|
|
1444
|
+
style: normalizeStyle({ transform: `translateY(${spanTops.value[widget.id] ?? 0}px)` }),
|
|
1445
|
+
role: widget.label ? "group" : void 0,
|
|
1446
|
+
"aria-label": widget.label,
|
|
1447
|
+
onWheel: onSpanWheel
|
|
1448
|
+
}, [createVNode(unref(render_part_default), { render: widget.render }, null, 8, ["render"])], 46, _hoisted_2);
|
|
1449
|
+
}), 128))], 6)) : createCommentVNode("", true)
|
|
763
1450
|
], 34)) : (openBlock(), createElementBlock("div", {
|
|
764
1451
|
key: 2,
|
|
765
1452
|
ref_key: "inlineBox",
|
|
@@ -770,6 +1457,8 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
770
1457
|
ref: editorInline,
|
|
771
1458
|
"model-value": unified.value?.text ?? "",
|
|
772
1459
|
language: __props.language,
|
|
1460
|
+
worker: __props.worker,
|
|
1461
|
+
"sync-highlight-lines": __props.syncHighlightLines,
|
|
773
1462
|
extensions: inlineExtensions,
|
|
774
1463
|
"tab-size": __props.tabSize,
|
|
775
1464
|
messages: unref(messages),
|
|
@@ -779,15 +1468,19 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
779
1468
|
foldable: false,
|
|
780
1469
|
"active-line": false,
|
|
781
1470
|
bordered: false,
|
|
1471
|
+
"scroll-y": __props.scrollY,
|
|
782
1472
|
wrap: __props.wrap,
|
|
783
1473
|
readonly: "",
|
|
784
1474
|
onTransaction: _cache[2] || (_cache[2] = ($event) => revealAt("inline", $event))
|
|
785
1475
|
}, null, 8, [
|
|
786
1476
|
"model-value",
|
|
787
1477
|
"language",
|
|
1478
|
+
"worker",
|
|
1479
|
+
"sync-highlight-lines",
|
|
788
1480
|
"tab-size",
|
|
789
1481
|
"messages",
|
|
790
1482
|
"aria-label",
|
|
1483
|
+
"scroll-y",
|
|
791
1484
|
"wrap"
|
|
792
1485
|
])], 2)),
|
|
793
1486
|
createElementVNode("div", {
|