@git-diff-view/react 0.0.13 → 0.0.14
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/cjs/index.development.js +56 -2164
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +56 -2127
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +2 -2
- package/dist/esm/index.mjs +22 -2109
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +726 -1
- package/package.json +10 -6
- package/dist/types/components/DiffAddWidget.d.ts +0 -21
- package/dist/types/components/DiffAddWidget.d.ts.map +0 -1
- package/dist/types/components/DiffContent.d.ts +0 -11
- package/dist/types/components/DiffContent.d.ts.map +0 -1
- package/dist/types/components/DiffExpand.d.ts +0 -11
- package/dist/types/components/DiffExpand.d.ts.map +0 -1
- package/dist/types/components/DiffNoNewLine.d.ts +0 -3
- package/dist/types/components/DiffNoNewLine.d.ts.map +0 -1
- package/dist/types/components/DiffSplitExtendLineNormal.d.ts +0 -10
- package/dist/types/components/DiffSplitExtendLineNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitExtendLineWrap.d.ts +0 -8
- package/dist/types/components/DiffSplitExtendLineWrap.d.ts.map +0 -1
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts +0 -10
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitHunkLineWrap.d.ts +0 -8
- package/dist/types/components/DiffSplitHunkLineWrap.d.ts.map +0 -1
- package/dist/types/components/DiffSplitLineNormal.d.ts +0 -10
- package/dist/types/components/DiffSplitLineNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitLineWrap.d.ts +0 -8
- package/dist/types/components/DiffSplitLineWrap.d.ts.map +0 -1
- package/dist/types/components/DiffSplitView.d.ts +0 -6
- package/dist/types/components/DiffSplitView.d.ts.map +0 -1
- package/dist/types/components/DiffSplitViewLineNormal.d.ts +0 -9
- package/dist/types/components/DiffSplitViewLineNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitViewLineWrap.d.ts +0 -7
- package/dist/types/components/DiffSplitViewLineWrap.d.ts.map +0 -1
- package/dist/types/components/DiffSplitViewNormal.d.ts +0 -6
- package/dist/types/components/DiffSplitViewNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitViewWrap.d.ts +0 -6
- package/dist/types/components/DiffSplitViewWrap.d.ts.map +0 -1
- package/dist/types/components/DiffSplitWidgetLineNormal.d.ts +0 -10
- package/dist/types/components/DiffSplitWidgetLineNormal.d.ts.map +0 -1
- package/dist/types/components/DiffSplitWidgetLineWrap.d.ts +0 -8
- package/dist/types/components/DiffSplitWidgetLineWrap.d.ts.map +0 -1
- package/dist/types/components/DiffUnifiedExtendLine.d.ts +0 -8
- package/dist/types/components/DiffUnifiedExtendLine.d.ts.map +0 -1
- package/dist/types/components/DiffUnifiedHunkLine.d.ts +0 -8
- package/dist/types/components/DiffUnifiedHunkLine.d.ts.map +0 -1
- package/dist/types/components/DiffUnifiedLine.d.ts +0 -8
- package/dist/types/components/DiffUnifiedLine.d.ts.map +0 -1
- package/dist/types/components/DiffUnifiedView.d.ts +0 -6
- package/dist/types/components/DiffUnifiedView.d.ts.map +0 -1
- package/dist/types/components/DiffUnifiedWidgetLine.d.ts +0 -8
- package/dist/types/components/DiffUnifiedWidgetLine.d.ts.map +0 -1
- package/dist/types/components/DiffView.d.ts +0 -69
- package/dist/types/components/DiffView.d.ts.map +0 -1
- package/dist/types/components/DiffViewContext.d.ts +0 -42
- package/dist/types/components/DiffViewContext.d.ts.map +0 -1
- package/dist/types/components/DiffWidgetContext.d.ts +0 -24
- package/dist/types/components/DiffWidgetContext.d.ts.map +0 -1
- package/dist/types/components/color.d.ts +0 -35
- package/dist/types/components/color.d.ts.map +0 -1
- package/dist/types/components/tools.d.ts +0 -5
- package/dist/types/components/tools.d.ts.map +0 -1
- package/dist/types/hooks/useCallbackRef.d.ts +0 -2
- package/dist/types/hooks/useCallbackRef.d.ts.map +0 -1
- package/dist/types/hooks/useDomWidth.d.ts +0 -5
- package/dist/types/hooks/useDomWidth.d.ts.map +0 -1
- package/dist/types/hooks/useSafeLayout.d.ts +0 -3
- package/dist/types/hooks/useSafeLayout.d.ts.map +0 -1
- package/dist/types/hooks/useSyncHeight.d.ts +0 -6
- package/dist/types/hooks/useSyncHeight.d.ts.map +0 -1
- package/dist/types/hooks/useTextWidth.d.ts +0 -17
- package/dist/types/hooks/useTextWidth.d.ts.map +0 -1
- package/dist/types/hooks/useUnmount.d.ts +0 -2
- package/dist/types/hooks/useUnmount.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.withStyle.d.ts +0 -6
- package/dist/types/index.withStyle.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var core = require('@git-diff-view/core');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var reactivityStore = require('reactivity-store');
|
|
6
|
-
var
|
|
6
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
7
7
|
var reactDom = require('react-dom');
|
|
8
8
|
|
|
9
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -54,13 +54,13 @@ function __rest(s, e) {
|
|
|
54
54
|
return t;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function __classPrivateFieldGet
|
|
57
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
58
58
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
59
59
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
60
60
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function __classPrivateFieldSet
|
|
63
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
64
64
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
65
65
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
66
66
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
@@ -72,2092 +72,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
72
72
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
exports.DiffHunkExpansionType = void 0;
|
|
76
|
-
(function (DiffHunkExpansionType) {
|
|
77
|
-
/** The hunk header cannot be expanded at all. */
|
|
78
|
-
DiffHunkExpansionType["None"] = "None";
|
|
79
|
-
/**
|
|
80
|
-
* The hunk header can be expanded up exclusively. Only the first hunk can be
|
|
81
|
-
* expanded up exclusively.
|
|
82
|
-
*/
|
|
83
|
-
DiffHunkExpansionType["Up"] = "Up";
|
|
84
|
-
/**
|
|
85
|
-
* The hunk header can be expanded down exclusively. Only the last hunk (if
|
|
86
|
-
* it's the dummy hunk with only one line) can be expanded down exclusively.
|
|
87
|
-
*/
|
|
88
|
-
DiffHunkExpansionType["Down"] = "Down";
|
|
89
|
-
/** The hunk header can be expanded both up and down. */
|
|
90
|
-
DiffHunkExpansionType["Both"] = "Both";
|
|
91
|
-
/**
|
|
92
|
-
* The hunk header represents a short gap that, when expanded, will
|
|
93
|
-
* result in merging this hunk and the hunk above.
|
|
94
|
-
*/
|
|
95
|
-
DiffHunkExpansionType["Short"] = "Short";
|
|
96
|
-
})(exports.DiffHunkExpansionType || (exports.DiffHunkExpansionType = {}));
|
|
97
|
-
/** each diff is made up of a number of hunks */
|
|
98
|
-
class DiffHunk {
|
|
99
|
-
/**
|
|
100
|
-
* @param header The details from the diff hunk header about the line start and patch length.
|
|
101
|
-
* @param lines The contents - context and changes - of the diff section.
|
|
102
|
-
* @param unifiedDiffStart The diff hunk's start position in the overall file diff.
|
|
103
|
-
* @param unifiedDiffEnd The diff hunk's end position in the overall file diff.
|
|
104
|
-
*/
|
|
105
|
-
constructor(header, lines, unifiedDiffStart, unifiedDiffEnd, expansionType) {
|
|
106
|
-
this.header = header;
|
|
107
|
-
this.lines = lines;
|
|
108
|
-
this.unifiedDiffStart = unifiedDiffStart;
|
|
109
|
-
this.unifiedDiffEnd = unifiedDiffEnd;
|
|
110
|
-
this.expansionType = expansionType;
|
|
111
|
-
}
|
|
112
|
-
equals(other) {
|
|
113
|
-
if (this === other) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return (this.header.equals(other.header) &&
|
|
117
|
-
this.unifiedDiffStart === other.unifiedDiffStart &&
|
|
118
|
-
this.unifiedDiffEnd === other.unifiedDiffEnd &&
|
|
119
|
-
this.expansionType === other.expansionType &&
|
|
120
|
-
this.lines.length === other.lines.length &&
|
|
121
|
-
this.lines.every((xLine, ix) => xLine.equals(other.lines[ix])));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/** details about the start and end of a diff hunk */
|
|
125
|
-
class DiffHunkHeader {
|
|
126
|
-
/**
|
|
127
|
-
* @param oldStartLine The line in the old (or original) file where this diff hunk starts.
|
|
128
|
-
* @param oldLineCount The number of lines in the old (or original) file that this diff hunk covers
|
|
129
|
-
* @param newStartLine The line in the new file where this diff hunk starts.
|
|
130
|
-
* @param newLineCount The number of lines in the new file that this diff hunk covers.
|
|
131
|
-
*/
|
|
132
|
-
constructor(oldStartLine, oldLineCount, newStartLine, newLineCount) {
|
|
133
|
-
this.oldStartLine = oldStartLine;
|
|
134
|
-
this.oldLineCount = oldLineCount;
|
|
135
|
-
this.newStartLine = newStartLine;
|
|
136
|
-
this.newLineCount = newLineCount;
|
|
137
|
-
}
|
|
138
|
-
toDiffLineRepresentation() {
|
|
139
|
-
return `@@ -${this.oldStartLine},${this.oldLineCount} +${this.newStartLine},${this.newLineCount} @@`;
|
|
140
|
-
}
|
|
141
|
-
equals(other) {
|
|
142
|
-
return (this.oldStartLine === other.oldStartLine &&
|
|
143
|
-
this.oldLineCount === other.oldLineCount &&
|
|
144
|
-
this.newStartLine === other.newStartLine &&
|
|
145
|
-
this.oldStartLine === other.oldStartLine);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
exports.NewLineSymbol = void 0;
|
|
150
|
-
(function (NewLineSymbol) {
|
|
151
|
-
NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
|
|
152
|
-
NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
|
|
153
|
-
NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
|
|
154
|
-
NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
|
|
155
|
-
})(exports.NewLineSymbol || (exports.NewLineSymbol = {}));
|
|
156
|
-
const maxLength = 1000;
|
|
157
|
-
/** Get the maximum position in the range. */
|
|
158
|
-
function rangeMax(range) {
|
|
159
|
-
return range.location + range.length;
|
|
160
|
-
}
|
|
161
|
-
/** Get the length of the common substring between the two strings. */
|
|
162
|
-
function commonLength(stringA, rangeA, stringB, rangeB, reverse) {
|
|
163
|
-
const max = Math.min(rangeA.length, rangeB.length);
|
|
164
|
-
const startA = reverse ? rangeMax(rangeA) - 1 : rangeA.location;
|
|
165
|
-
const startB = reverse ? rangeMax(rangeB) - 1 : rangeB.location;
|
|
166
|
-
const stride = reverse ? -1 : 1;
|
|
167
|
-
let length = 0;
|
|
168
|
-
while (Math.abs(length) < max) {
|
|
169
|
-
if (stringA[startA + length] !== stringB[startB + length]) {
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
length += stride;
|
|
173
|
-
}
|
|
174
|
-
return Math.abs(length);
|
|
175
|
-
}
|
|
176
|
-
function isInValidString(s) {
|
|
177
|
-
return s.trim().length === 0 || s.length >= maxLength;
|
|
178
|
-
}
|
|
179
|
-
// TODO maybe could use the original content line
|
|
180
|
-
/** Get the changed ranges in the strings, relative to each other. */
|
|
181
|
-
function relativeChanges(addition, deletion) {
|
|
182
|
-
const stringA = addition.text;
|
|
183
|
-
const stringB = deletion.text;
|
|
184
|
-
let bRange = { location: 0, length: stringB.length };
|
|
185
|
-
let aRange = { location: 0, length: stringA.length };
|
|
186
|
-
const _stringA = stringA.trimEnd();
|
|
187
|
-
const _stringB = stringB.trimEnd();
|
|
188
|
-
const aEndStr = stringA.slice(-2);
|
|
189
|
-
const bEndStr = stringB.slice(-2);
|
|
190
|
-
const hasNewLineChanged = addition.noTrailingNewLine !== deletion.noTrailingNewLine;
|
|
191
|
-
const aSymbol = aEndStr === "\r\n" ? exports.NewLineSymbol.CRLF : aEndStr.endsWith("\r") ? exports.NewLineSymbol.CR : exports.NewLineSymbol.LF;
|
|
192
|
-
const bSymbol = bEndStr === "\r\n" ? exports.NewLineSymbol.CRLF : bEndStr.endsWith("\r") ? exports.NewLineSymbol.CR : exports.NewLineSymbol.LF;
|
|
193
|
-
if (_stringA === _stringB && (hasNewLineChanged || aSymbol !== bSymbol)) {
|
|
194
|
-
return {
|
|
195
|
-
stringARange: {
|
|
196
|
-
location: _stringA.length,
|
|
197
|
-
length: stringA.length - _stringA.length,
|
|
198
|
-
newLineSymbol: hasNewLineChanged ? exports.NewLineSymbol.NEWLINE : aSymbol,
|
|
199
|
-
},
|
|
200
|
-
stringBRange: {
|
|
201
|
-
location: _stringB.length,
|
|
202
|
-
length: stringB.length - _stringB.length,
|
|
203
|
-
newLineSymbol: hasNewLineChanged ? exports.NewLineSymbol.NEWLINE : bSymbol,
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
if (isInValidString(stringA) || isInValidString(stringB)) {
|
|
208
|
-
aRange.length = 0;
|
|
209
|
-
bRange.length = 0;
|
|
210
|
-
return { stringARange: aRange, stringBRange: bRange };
|
|
211
|
-
}
|
|
212
|
-
const prefixLength = commonLength(stringB, bRange, stringA, aRange, false);
|
|
213
|
-
bRange = {
|
|
214
|
-
location: bRange.location + prefixLength,
|
|
215
|
-
length: bRange.length - prefixLength,
|
|
216
|
-
};
|
|
217
|
-
aRange = {
|
|
218
|
-
location: aRange.location + prefixLength,
|
|
219
|
-
length: aRange.length - prefixLength,
|
|
220
|
-
};
|
|
221
|
-
const suffixLength = commonLength(stringB, bRange, stringA, aRange, true);
|
|
222
|
-
bRange.length -= suffixLength;
|
|
223
|
-
aRange.length -= suffixLength;
|
|
224
|
-
return { stringARange: aRange, stringBRange: bRange };
|
|
225
|
-
}
|
|
226
|
-
/** Check two string have a diff range */
|
|
227
|
-
function hasRelativeChange(addition, deletion) {
|
|
228
|
-
const _stringA = addition.text.trim();
|
|
229
|
-
const _stringB = deletion.text.trim();
|
|
230
|
-
const _addition = addition.clone(_stringA);
|
|
231
|
-
const _deletion = deletion.clone(_stringB);
|
|
232
|
-
const { stringARange, stringBRange } = relativeChanges(_addition, _deletion);
|
|
233
|
-
return (stringARange.location > 0 ||
|
|
234
|
-
stringBRange.location > 0 ||
|
|
235
|
-
stringARange.length < _stringA.length ||
|
|
236
|
-
stringBRange.length < _stringB.length);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** indicate what a line in the diff represents */
|
|
240
|
-
exports.DiffLineType = void 0;
|
|
241
|
-
(function (DiffLineType) {
|
|
242
|
-
DiffLineType[DiffLineType["Context"] = 0] = "Context";
|
|
243
|
-
DiffLineType[DiffLineType["Add"] = 1] = "Add";
|
|
244
|
-
DiffLineType[DiffLineType["Delete"] = 2] = "Delete";
|
|
245
|
-
DiffLineType[DiffLineType["Hunk"] = 3] = "Hunk";
|
|
246
|
-
})(exports.DiffLineType || (exports.DiffLineType = {}));
|
|
247
|
-
/** track details related to each line in the diff */
|
|
248
|
-
class DiffLine {
|
|
249
|
-
constructor(text, type,
|
|
250
|
-
// Line number in the original diff patch (before expanding it), or null if
|
|
251
|
-
// it was added as part of a diff expansion action.
|
|
252
|
-
originalLineNumber, oldLineNumber, newLineNumber, noTrailingNewLine = false, needRematch = false, range) {
|
|
253
|
-
this.text = text;
|
|
254
|
-
this.type = type;
|
|
255
|
-
this.originalLineNumber = originalLineNumber;
|
|
256
|
-
this.oldLineNumber = oldLineNumber;
|
|
257
|
-
this.newLineNumber = newLineNumber;
|
|
258
|
-
this.noTrailingNewLine = noTrailingNewLine;
|
|
259
|
-
this.needRematch = needRematch;
|
|
260
|
-
this.range = range;
|
|
261
|
-
}
|
|
262
|
-
withNoTrailingNewLine(noTrailingNewLine) {
|
|
263
|
-
return new DiffLine(this.text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber, noTrailingNewLine);
|
|
264
|
-
}
|
|
265
|
-
isIncludeableLine() {
|
|
266
|
-
return this.type === exports.DiffLineType.Add || this.type === exports.DiffLineType.Delete;
|
|
267
|
-
}
|
|
268
|
-
/** The content of the line, i.e., without the line type marker. */
|
|
269
|
-
get content() {
|
|
270
|
-
return this.text.substring(1);
|
|
271
|
-
}
|
|
272
|
-
equals(other) {
|
|
273
|
-
return (this.text === other.text &&
|
|
274
|
-
this.type === other.type &&
|
|
275
|
-
this.originalLineNumber === other.originalLineNumber &&
|
|
276
|
-
this.oldLineNumber === other.oldLineNumber &&
|
|
277
|
-
this.newLineNumber === other.newLineNumber &&
|
|
278
|
-
this.noTrailingNewLine === other.noTrailingNewLine);
|
|
279
|
-
}
|
|
280
|
-
clone(text) {
|
|
281
|
-
return new DiffLine(text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const checkDiffLineIncludeChange = (diffLine) => {
|
|
285
|
-
if (!diffLine)
|
|
286
|
-
return false;
|
|
287
|
-
return diffLine.type === exports.DiffLineType.Add || diffLine.type === exports.DiffLineType.Delete;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
/** How many new lines will be added to a diff hunk by default. */
|
|
291
|
-
const DefaultDiffExpansionStep = 40;
|
|
292
|
-
function assertNever(_, message) {
|
|
293
|
-
throw new Error(message);
|
|
294
|
-
}
|
|
295
|
-
/** Utility function for getting the digit count of the largest line number in an array of diff hunks */
|
|
296
|
-
function getLargestLineNumber(hunks) {
|
|
297
|
-
var _a, _b;
|
|
298
|
-
if (hunks.length === 0) {
|
|
299
|
-
return 0;
|
|
300
|
-
}
|
|
301
|
-
for (let i = hunks.length - 1; i >= 0; i--) {
|
|
302
|
-
const hunk = hunks[i];
|
|
303
|
-
for (let j = hunk.lines.length - 1; j >= 0; j--) {
|
|
304
|
-
const line = hunk.lines[j];
|
|
305
|
-
if (line.type === exports.DiffLineType.Hunk) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
const newLineNumber = (_a = line.newLineNumber) !== null && _a !== void 0 ? _a : 0;
|
|
309
|
-
const oldLineNumber = (_b = line.oldLineNumber) !== null && _b !== void 0 ? _b : 0;
|
|
310
|
-
return newLineNumber > oldLineNumber ? newLineNumber : oldLineNumber;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return 0;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Calculates whether or not a hunk header can be expanded up, down, both, or if
|
|
317
|
-
* the space represented by the hunk header is short and expansion there would
|
|
318
|
-
* mean merging with the hunk above.
|
|
319
|
-
*
|
|
320
|
-
* @param hunkIndex Index of the hunk to evaluate within the whole diff.
|
|
321
|
-
* @param hunkHeader Header of the hunk to evaluate.
|
|
322
|
-
* @param previousHunk Hunk previous to the one to evaluate. Null if the
|
|
323
|
-
* evaluated hunk is the first one.
|
|
324
|
-
*/
|
|
325
|
-
function getHunkHeaderExpansionType(hunkIndex, hunkHeader, previousHunk) {
|
|
326
|
-
const distanceToPrevious = previousHunk === null
|
|
327
|
-
? Infinity
|
|
328
|
-
: hunkHeader.oldStartLine - previousHunk.header.oldStartLine - previousHunk.header.oldLineCount;
|
|
329
|
-
// In order to simplify the whole logic around expansion, only the hunk at the
|
|
330
|
-
// top can be expanded up exclusively, and only the hunk at the bottom (the
|
|
331
|
-
// dummy one, see getTextDiffWithBottomDummyHunk) can be expanded down
|
|
332
|
-
// exclusively.
|
|
333
|
-
// The rest of the hunks can be expanded both ways, except those which are too
|
|
334
|
-
// short and therefore the direction of expansion doesn't matter.
|
|
335
|
-
if (hunkIndex === 0) {
|
|
336
|
-
// The top hunk can only be expanded if there is content above it
|
|
337
|
-
if (hunkHeader.oldStartLine > 1 && hunkHeader.newStartLine > 1) {
|
|
338
|
-
return exports.DiffHunkExpansionType.Up;
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
return exports.DiffHunkExpansionType.None;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
else if (distanceToPrevious <= DefaultDiffExpansionStep) {
|
|
345
|
-
return exports.DiffHunkExpansionType.Short;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
return exports.DiffHunkExpansionType.Both;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const numIterator = (num, cb) => {
|
|
352
|
-
const re = [];
|
|
353
|
-
for (let i = 0; i < num; i++) {
|
|
354
|
-
re.push(cb(i));
|
|
355
|
-
}
|
|
356
|
-
return re;
|
|
357
|
-
};
|
|
358
|
-
const getLang = (fileName) => {
|
|
359
|
-
const dotIndex = fileName.lastIndexOf(".");
|
|
360
|
-
const extension = fileName.slice(dotIndex + 1);
|
|
361
|
-
return extension;
|
|
362
|
-
};
|
|
363
|
-
const getDiffRange = (additions, deletions) => {
|
|
364
|
-
if (additions.length === deletions.length) {
|
|
365
|
-
const len = additions.length;
|
|
366
|
-
for (let i = 0; i < len; i++) {
|
|
367
|
-
const addition = additions[i];
|
|
368
|
-
const deletion = deletions[i];
|
|
369
|
-
const hasDiffRange = hasRelativeChange(addition, deletion);
|
|
370
|
-
if (hasDiffRange) {
|
|
371
|
-
const { stringARange, stringBRange } = relativeChanges(addition, deletion);
|
|
372
|
-
addition.needRematch = true;
|
|
373
|
-
addition.range = stringARange;
|
|
374
|
-
deletion.needRematch = true;
|
|
375
|
-
deletion.range = stringBRange;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/* eslint-disable max-lines */
|
|
382
|
-
// !NOTE: ALL of the diff parse logic copy from desktop, SEE https://github.com/desktop/desktop
|
|
383
|
-
// https://en.wikipedia.org/wiki/Diff_utility
|
|
384
|
-
//
|
|
385
|
-
// @@ -l,s +l,s @@ optional section heading
|
|
386
|
-
//
|
|
387
|
-
// The hunk range information contains two hunk ranges. The range for the hunk of the original
|
|
388
|
-
// file is preceded by a minus symbol, and the range for the new file is preceded by a plus
|
|
389
|
-
// symbol. Each hunk range is of the format l,s where l is the starting line number and s is
|
|
390
|
-
// the number of lines the change hunk applies to for each respective file.
|
|
391
|
-
//
|
|
392
|
-
// In many versions of GNU diff, each range can omit the comma and trailing value s,
|
|
393
|
-
// in which case s defaults to 1
|
|
394
|
-
const diffHeaderRe = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
395
|
-
/**
|
|
396
|
-
* Regular expression matching invisible bidirectional Unicode characters that
|
|
397
|
-
* may be interpreted or compiled differently than what it appears. More info:
|
|
398
|
-
* https://github.co/hiddenchars
|
|
399
|
-
*/
|
|
400
|
-
const HiddenBidiCharsRegex = /[\u202A-\u202E]|[\u2066-\u2069]/;
|
|
401
|
-
const DiffPrefixAdd = "+";
|
|
402
|
-
const DiffPrefixDelete = "-";
|
|
403
|
-
const DiffPrefixContext = " ";
|
|
404
|
-
const DiffPrefixNoNewline = "\\";
|
|
405
|
-
const DiffLinePrefixChars = new Set([
|
|
406
|
-
DiffPrefixAdd,
|
|
407
|
-
DiffPrefixDelete,
|
|
408
|
-
DiffPrefixContext,
|
|
409
|
-
DiffPrefixNoNewline,
|
|
410
|
-
]);
|
|
411
|
-
/**
|
|
412
|
-
* A parser for the GNU unified diff format
|
|
413
|
-
*
|
|
414
|
-
* See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
|
|
415
|
-
*/
|
|
416
|
-
class DiffParser {
|
|
417
|
-
constructor() {
|
|
418
|
-
Object.defineProperty(this, "__v_skip", { value: true });
|
|
419
|
-
this.reset();
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Resets the internal parser state so that it can be reused.
|
|
423
|
-
*
|
|
424
|
-
* This is done automatically at the end of each parse run.
|
|
425
|
-
*/
|
|
426
|
-
reset() {
|
|
427
|
-
this.ls = 0;
|
|
428
|
-
this.le = -1;
|
|
429
|
-
this.text = "";
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Aligns the internal character pointers at the boundaries of
|
|
433
|
-
* the next line.
|
|
434
|
-
*
|
|
435
|
-
* Returns true if successful or false if the end of the diff
|
|
436
|
-
* has been reached.
|
|
437
|
-
*/
|
|
438
|
-
nextLine() {
|
|
439
|
-
this.ls = this.le + 1;
|
|
440
|
-
// We've reached the end of the diff
|
|
441
|
-
if (this.ls >= this.text.length) {
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
this.le = this.text.indexOf("\n", this.ls);
|
|
445
|
-
// If we can't find the next newline character we'll put our
|
|
446
|
-
// end pointer at the end of the diff string
|
|
447
|
-
if (this.le === -1) {
|
|
448
|
-
this.le = this.text.length;
|
|
449
|
-
}
|
|
450
|
-
// We've succeeded if there's anything to read in between the
|
|
451
|
-
// start and the end
|
|
452
|
-
return this.ls !== this.le;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Advances to the next line and returns it as a substring
|
|
456
|
-
* of the raw diff text. Returns null if end of diff was
|
|
457
|
-
* reached.
|
|
458
|
-
*/
|
|
459
|
-
readLine(header) {
|
|
460
|
-
if (header) {
|
|
461
|
-
return this.nextLine() ? this.text.substring(this.ls, this.le) : null;
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
return this.nextLine() ? this.text.substring(this.ls + 1, this.le + 1) : null;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
/** Tests if the current line starts with the given search text */
|
|
468
|
-
lineStartsWith(searchString) {
|
|
469
|
-
return this.text.startsWith(searchString, this.ls);
|
|
470
|
-
}
|
|
471
|
-
/** Tests if the current line ends with the given search text */
|
|
472
|
-
lineEndsWith(searchString) {
|
|
473
|
-
return this.text.endsWith(searchString, this.le);
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Returns the starting character of the next line without
|
|
477
|
-
* advancing the internal state. Returns null if advancing
|
|
478
|
-
* would mean reaching the end of the diff.
|
|
479
|
-
*/
|
|
480
|
-
peek() {
|
|
481
|
-
const p = this.le + 1;
|
|
482
|
-
return p < this.text.length ? this.text[p] : null;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Parse the diff header, meaning everything from the
|
|
486
|
-
* start of the diff output to the end of the line beginning
|
|
487
|
-
* with +++
|
|
488
|
-
*
|
|
489
|
-
* Example diff header:
|
|
490
|
-
*
|
|
491
|
-
* diff --git a/app/src/lib/diff-parser.ts b/app/src/lib/diff-parser.ts
|
|
492
|
-
* index e1d4871..3bd3ee0 100644
|
|
493
|
-
* --- a/app/src/lib/diff-parser.ts
|
|
494
|
-
* +++ b/app/src/lib/diff-parser.ts
|
|
495
|
-
*
|
|
496
|
-
* Returns an object with information extracted from the diff
|
|
497
|
-
* header (currently whether it's a binary patch) or null if
|
|
498
|
-
* the end of the diff was reached before the +++ line could be
|
|
499
|
-
* found (which is a valid state).
|
|
500
|
-
*/
|
|
501
|
-
parseDiffHeader() {
|
|
502
|
-
// TODO: There's information in here that we might want to
|
|
503
|
-
// capture, such as mode changes
|
|
504
|
-
while (this.nextLine()) {
|
|
505
|
-
if (this.lineStartsWith("Binary files ") && this.lineEndsWith("differ")) {
|
|
506
|
-
return { isBinary: true };
|
|
507
|
-
}
|
|
508
|
-
if (this.lineStartsWith("+++")) {
|
|
509
|
-
return { isBinary: false };
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
// It's not an error to not find the +++ line, see the
|
|
513
|
-
// 'parses diff of empty file' test in diff-parser-tests.ts
|
|
514
|
-
return null;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Attempts to convert a RegExp capture group into a number.
|
|
518
|
-
* If the group doesn't exist or wasn't captured the function
|
|
519
|
-
* will return the value of the defaultValue parameter or throw
|
|
520
|
-
* an error if no default value was provided. If the captured
|
|
521
|
-
* string can't be converted to a number an error will be thrown.
|
|
522
|
-
*/
|
|
523
|
-
numberFromGroup(m, group, defaultValue = null) {
|
|
524
|
-
const str = m[group];
|
|
525
|
-
if (!str) {
|
|
526
|
-
if (!defaultValue) {
|
|
527
|
-
throw new Error(`Group ${group} missing from regexp match and no defaultValue was provided`);
|
|
528
|
-
}
|
|
529
|
-
return defaultValue;
|
|
530
|
-
}
|
|
531
|
-
const num = parseInt(str, 10);
|
|
532
|
-
if (isNaN(num)) {
|
|
533
|
-
throw new Error(`Could not parse capture group ${group} into number: ${str}`);
|
|
534
|
-
}
|
|
535
|
-
return num;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Parses a hunk header or throws an error if the given line isn't
|
|
539
|
-
* a well-formed hunk header.
|
|
540
|
-
*
|
|
541
|
-
* We currently only extract the line number information and
|
|
542
|
-
* ignore any hunk headings.
|
|
543
|
-
*
|
|
544
|
-
* Example hunk header (text within ``):
|
|
545
|
-
*
|
|
546
|
-
* `@@ -84,10 +82,8 @@ export function parseRawDiff(lines: ReadonlyArray<string>): Diff {`
|
|
547
|
-
*
|
|
548
|
-
* Where everything after the last @@ is what's known as the hunk, or section, heading
|
|
549
|
-
*/
|
|
550
|
-
parseHunkHeader(line) {
|
|
551
|
-
const m = diffHeaderRe.exec(line);
|
|
552
|
-
if (!m) {
|
|
553
|
-
throw new Error(`Invalid hunk header format`);
|
|
554
|
-
}
|
|
555
|
-
// If endLines are missing default to 1, see diffHeaderRe docs
|
|
556
|
-
const oldStartLine = this.numberFromGroup(m, 1);
|
|
557
|
-
const oldLineCount = this.numberFromGroup(m, 2, 1);
|
|
558
|
-
const newStartLine = this.numberFromGroup(m, 3);
|
|
559
|
-
const newLineCount = this.numberFromGroup(m, 4, 1);
|
|
560
|
-
return new DiffHunkHeader(oldStartLine, oldLineCount, newStartLine, newLineCount);
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Convenience function which lets us leverage the type system to
|
|
564
|
-
* prove exhaustive checks in parseHunk.
|
|
565
|
-
*
|
|
566
|
-
* Takes an arbitrary string and checks to see if the first character
|
|
567
|
-
* of that string is one of the allowed prefix characters for diff
|
|
568
|
-
* lines (ie lines in between hunk headers).
|
|
569
|
-
*/
|
|
570
|
-
parseLinePrefix(c) {
|
|
571
|
-
// Since we know that DiffLinePrefixChars and the DiffLinePrefix type
|
|
572
|
-
// include the same characters we can tell the type system that we
|
|
573
|
-
// now know that c[0] is one of the characters in the DifflinePrefix set
|
|
574
|
-
if (c && c.length && DiffLinePrefixChars.has(c[0])) {
|
|
575
|
-
return c[0];
|
|
576
|
-
}
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Parses a hunk, including its header or throws an error if the diff doesn't
|
|
581
|
-
* contain a well-formed diff hunk at the current position.
|
|
582
|
-
*
|
|
583
|
-
* Expects that the position has been advanced to the beginning of a presumed
|
|
584
|
-
* diff hunk header.
|
|
585
|
-
*
|
|
586
|
-
* @param linesConsumed The number of unified diff lines consumed up until
|
|
587
|
-
* this point by the diff parser. Used to give the
|
|
588
|
-
* position and length (in lines) of the parsed hunk
|
|
589
|
-
* relative to the overall parsed diff. These numbers
|
|
590
|
-
* have no real meaning in the context of a diff and
|
|
591
|
-
* are only used to aid the app in line-selections.
|
|
592
|
-
*/
|
|
593
|
-
parseHunk(linesConsumed, hunkIndex, previousHunk) {
|
|
594
|
-
const headerLine = this.readLine(true);
|
|
595
|
-
if (!headerLine) {
|
|
596
|
-
throw new Error("Expected hunk header but reached end of diff");
|
|
597
|
-
}
|
|
598
|
-
const header = this.parseHunkHeader(headerLine);
|
|
599
|
-
const lines = new Array();
|
|
600
|
-
lines.push(new DiffLine(headerLine, exports.DiffLineType.Hunk, 1, null, null));
|
|
601
|
-
let c;
|
|
602
|
-
let rollingDiffBeforeCounter = header.oldStartLine;
|
|
603
|
-
let rollingDiffAfterCounter = header.newStartLine;
|
|
604
|
-
let diffLineNumber = linesConsumed;
|
|
605
|
-
while ((c = this.parseLinePrefix(this.peek()))) {
|
|
606
|
-
const line = this.readLine(false);
|
|
607
|
-
diffLineNumber++;
|
|
608
|
-
if (!line) {
|
|
609
|
-
throw new Error("Expected unified diff line but reached end of diff");
|
|
610
|
-
}
|
|
611
|
-
// A marker indicating that the last line in the original or the new file
|
|
612
|
-
// is missing a trailing newline. In other words, the presence of this marker
|
|
613
|
-
// means that the new and/or original file lacks a trailing newline.
|
|
614
|
-
//
|
|
615
|
-
// When we find it we have to look up the previous line and set the
|
|
616
|
-
// noTrailingNewLine flag
|
|
617
|
-
if (c === DiffPrefixNoNewline) {
|
|
618
|
-
// See https://github.com/git/git/blob/21f862b498925194f8f1ebe8203b7a7df756555b/apply.c#L1725-L1732
|
|
619
|
-
if (line.length < 12) {
|
|
620
|
-
throw new Error(`Expected "no newline at end of file" marker to be at least 12 bytes long`);
|
|
621
|
-
}
|
|
622
|
-
const previousLineIndex = lines.length - 1;
|
|
623
|
-
const previousLine = lines[previousLineIndex];
|
|
624
|
-
lines[previousLineIndex] = previousLine.withNoTrailingNewLine(true);
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
let diffLine;
|
|
628
|
-
if (c === DiffPrefixAdd) {
|
|
629
|
-
diffLine = new DiffLine(line, exports.DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
|
|
630
|
-
}
|
|
631
|
-
else if (c === DiffPrefixDelete) {
|
|
632
|
-
diffLine = new DiffLine(line, exports.DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
|
|
633
|
-
}
|
|
634
|
-
else if (c === DiffPrefixContext) {
|
|
635
|
-
diffLine = new DiffLine(line, exports.DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
|
|
636
|
-
}
|
|
637
|
-
else {
|
|
638
|
-
return assertNever(c, `Unknown DiffLinePrefix: ${c}`);
|
|
639
|
-
}
|
|
640
|
-
lines.push(diffLine);
|
|
641
|
-
}
|
|
642
|
-
if (lines.length === 1) {
|
|
643
|
-
throw new Error("Malformed diff, empty hunk");
|
|
644
|
-
}
|
|
645
|
-
return new DiffHunk(header, lines, linesConsumed, linesConsumed + lines.length - 1, getHunkHeaderExpansionType(hunkIndex, header, previousHunk));
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Parse a well-formed unified diff into hunks and lines.
|
|
649
|
-
*
|
|
650
|
-
* @param text A unified diff produced by git diff, git log --patch
|
|
651
|
-
* or any other git plumbing command that produces unified
|
|
652
|
-
* diffs.
|
|
653
|
-
*/
|
|
654
|
-
parse(text) {
|
|
655
|
-
this.text = text;
|
|
656
|
-
try {
|
|
657
|
-
const headerInfo = this.parseDiffHeader();
|
|
658
|
-
const headerEnd = this.le;
|
|
659
|
-
const header = this.text.substring(0, headerEnd);
|
|
660
|
-
// empty diff
|
|
661
|
-
if (!headerInfo) {
|
|
662
|
-
return {
|
|
663
|
-
header,
|
|
664
|
-
contents: "",
|
|
665
|
-
hunks: [],
|
|
666
|
-
isBinary: false,
|
|
667
|
-
maxLineNumber: 0,
|
|
668
|
-
hasHiddenBidiChars: false,
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
if (headerInfo.isBinary) {
|
|
672
|
-
return {
|
|
673
|
-
header,
|
|
674
|
-
contents: "",
|
|
675
|
-
hunks: [],
|
|
676
|
-
isBinary: true,
|
|
677
|
-
maxLineNumber: 0,
|
|
678
|
-
hasHiddenBidiChars: false,
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
const hunks = new Array();
|
|
682
|
-
let linesConsumed = 0;
|
|
683
|
-
let previousHunk = null;
|
|
684
|
-
do {
|
|
685
|
-
const hunk = this.parseHunk(linesConsumed, hunks.length, previousHunk);
|
|
686
|
-
hunks.push(hunk);
|
|
687
|
-
previousHunk = hunk;
|
|
688
|
-
linesConsumed += hunk.lines.length;
|
|
689
|
-
} while (this.peek());
|
|
690
|
-
const contents = this.text
|
|
691
|
-
.substring(headerEnd + 1, this.le)
|
|
692
|
-
// Note that this simply returns a reference to the
|
|
693
|
-
// substring if no match is found, it does not create
|
|
694
|
-
// a new string instance.
|
|
695
|
-
.replace(/\n\/g, "");
|
|
696
|
-
return {
|
|
697
|
-
header,
|
|
698
|
-
contents,
|
|
699
|
-
hunks,
|
|
700
|
-
isBinary: headerInfo.isBinary,
|
|
701
|
-
maxLineNumber: getLargestLineNumber(hunks),
|
|
702
|
-
hasHiddenBidiChars: HiddenBidiCharsRegex.test(text),
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
finally {
|
|
706
|
-
this.reset();
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
const parseInstance = new DiffParser();
|
|
711
|
-
|
|
712
|
-
/******************************************************************************
|
|
713
|
-
Copyright (c) Microsoft Corporation.
|
|
714
|
-
|
|
715
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
716
|
-
purpose with or without fee is hereby granted.
|
|
717
|
-
|
|
718
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
719
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
720
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
721
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
722
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
723
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
724
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
725
|
-
***************************************************************************** */
|
|
726
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
730
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
731
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
732
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
736
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
737
|
-
return (state.set(receiver, value)), value;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
741
|
-
var e = new Error(message);
|
|
742
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
const processAST = (ast) => {
|
|
746
|
-
let lineNumber = 1;
|
|
747
|
-
const syntaxObj = {};
|
|
748
|
-
const loopAST = (nodes, wrapper) => {
|
|
749
|
-
nodes.forEach((node) => {
|
|
750
|
-
if (node.type === "text") {
|
|
751
|
-
if (node.value.indexOf("\n") === -1) {
|
|
752
|
-
const valueLength = node.value.length;
|
|
753
|
-
if (!syntaxObj[lineNumber]) {
|
|
754
|
-
node.startIndex = 0;
|
|
755
|
-
node.endIndex = valueLength - 1;
|
|
756
|
-
const item = {
|
|
757
|
-
value: node.value,
|
|
758
|
-
lineNumber,
|
|
759
|
-
valueLength,
|
|
760
|
-
nodeList: [{ node, wrapper }],
|
|
761
|
-
};
|
|
762
|
-
syntaxObj[lineNumber] = item;
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
766
|
-
node.endIndex = node.startIndex + valueLength - 1;
|
|
767
|
-
syntaxObj[lineNumber].value += node.value;
|
|
768
|
-
syntaxObj[lineNumber].valueLength += valueLength;
|
|
769
|
-
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
770
|
-
}
|
|
771
|
-
node.lineNumber = lineNumber;
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
const lines = node.value.split("\n");
|
|
775
|
-
node.children = node.children || [];
|
|
776
|
-
for (let i = 0; i < lines.length; i++) {
|
|
777
|
-
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
778
|
-
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
779
|
-
const _valueLength = _value.length;
|
|
780
|
-
const _node = {
|
|
781
|
-
type: "text",
|
|
782
|
-
value: _value,
|
|
783
|
-
startIndex: Infinity,
|
|
784
|
-
endIndex: Infinity,
|
|
785
|
-
lineNumber: _lineNumber,
|
|
786
|
-
};
|
|
787
|
-
if (!syntaxObj[_lineNumber]) {
|
|
788
|
-
_node.startIndex = 0;
|
|
789
|
-
_node.endIndex = _valueLength - 1;
|
|
790
|
-
const item = {
|
|
791
|
-
value: _value,
|
|
792
|
-
lineNumber: _lineNumber,
|
|
793
|
-
valueLength: _valueLength,
|
|
794
|
-
nodeList: [{ node: _node, wrapper }],
|
|
795
|
-
};
|
|
796
|
-
syntaxObj[_lineNumber] = item;
|
|
797
|
-
}
|
|
798
|
-
else {
|
|
799
|
-
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
800
|
-
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
801
|
-
syntaxObj[_lineNumber].value += _value;
|
|
802
|
-
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
803
|
-
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
804
|
-
}
|
|
805
|
-
node.children.push(_node);
|
|
806
|
-
}
|
|
807
|
-
node.lineNumber = lineNumber;
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
if (node.children) {
|
|
811
|
-
loopAST(node.children, node);
|
|
812
|
-
node.lineNumber = lineNumber;
|
|
813
|
-
}
|
|
814
|
-
});
|
|
815
|
-
};
|
|
816
|
-
loopAST(ast.children);
|
|
817
|
-
return { syntaxFileObject: syntaxObj, syntaxFileLineNumber: lineNumber };
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
const lowlight = lowlight$1.createLowlight(lowlight$1.all);
|
|
821
|
-
// !SEE https://github.com/highlightjs/highlightjs-vue
|
|
822
|
-
lowlight.register("vue", function hljsDefineVue(hljs) {
|
|
823
|
-
return {
|
|
824
|
-
subLanguage: "xml",
|
|
825
|
-
contains: [
|
|
826
|
-
hljs.COMMENT("<!--", "-->", {
|
|
827
|
-
relevance: 10,
|
|
828
|
-
}),
|
|
829
|
-
{
|
|
830
|
-
begin: /^(\s*)(<script>)/gm,
|
|
831
|
-
end: /^(\s*)(<\/script>)/gm,
|
|
832
|
-
subLanguage: "javascript",
|
|
833
|
-
excludeBegin: true,
|
|
834
|
-
excludeEnd: true,
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
begin: /^(?:\s*)(?:<script\s+lang=(["'])ts\1>)/gm,
|
|
838
|
-
end: /^(\s*)(<\/script>)/gm,
|
|
839
|
-
subLanguage: "typescript",
|
|
840
|
-
excludeBegin: true,
|
|
841
|
-
excludeEnd: true,
|
|
842
|
-
},
|
|
843
|
-
{
|
|
844
|
-
begin: /^(\s*)(<style(\s+scoped)?>)/gm,
|
|
845
|
-
end: /^(\s*)(<\/style>)/gm,
|
|
846
|
-
subLanguage: "css",
|
|
847
|
-
excludeBegin: true,
|
|
848
|
-
excludeEnd: true,
|
|
849
|
-
},
|
|
850
|
-
{
|
|
851
|
-
begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])(?:s[ca]ss)\1(?:\s+scoped)?>)/gm,
|
|
852
|
-
end: /^(\s*)(<\/style>)/gm,
|
|
853
|
-
subLanguage: "scss",
|
|
854
|
-
excludeBegin: true,
|
|
855
|
-
excludeEnd: true,
|
|
856
|
-
},
|
|
857
|
-
{
|
|
858
|
-
begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])stylus\1(?:\s+scoped)?>)/gm,
|
|
859
|
-
end: /^(\s*)(<\/style>)/gm,
|
|
860
|
-
subLanguage: "stylus",
|
|
861
|
-
excludeBegin: true,
|
|
862
|
-
excludeEnd: true,
|
|
863
|
-
},
|
|
864
|
-
],
|
|
865
|
-
};
|
|
866
|
-
});
|
|
867
|
-
const instance = { name: "lowlight" };
|
|
868
|
-
let _maxLineToIgnoreSyntax = 2000;
|
|
869
|
-
const _ignoreSyntaxHighlightList = [];
|
|
870
|
-
Object.defineProperty(instance, "maxLineToIgnoreSyntax", {
|
|
871
|
-
get: () => _maxLineToIgnoreSyntax,
|
|
872
|
-
});
|
|
873
|
-
Object.defineProperty(instance, "setMaxLineToIgnoreSyntax", {
|
|
874
|
-
value: (v) => {
|
|
875
|
-
_maxLineToIgnoreSyntax = v;
|
|
876
|
-
},
|
|
877
|
-
});
|
|
878
|
-
Object.defineProperty(instance, "ignoreSyntaxHighlightList", {
|
|
879
|
-
get: () => _ignoreSyntaxHighlightList,
|
|
880
|
-
});
|
|
881
|
-
Object.defineProperty(instance, "setIgnoreSyntaxHighlightList", {
|
|
882
|
-
value: (v) => {
|
|
883
|
-
_ignoreSyntaxHighlightList.length = 0;
|
|
884
|
-
_ignoreSyntaxHighlightList.push(...v);
|
|
885
|
-
},
|
|
886
|
-
});
|
|
887
|
-
Object.defineProperty(instance, "getAST", {
|
|
888
|
-
value: (raw, fileName, lang) => {
|
|
889
|
-
let hasRegisteredLang = true;
|
|
890
|
-
if (!lowlight.registered(lang)) {
|
|
891
|
-
console.warn(`not support current lang: ${lang} yet`);
|
|
892
|
-
hasRegisteredLang = false;
|
|
893
|
-
}
|
|
894
|
-
if (fileName &&
|
|
895
|
-
highlighter.ignoreSyntaxHighlightList.some((item) => item instanceof RegExp ? item.test(fileName) : fileName === item)) {
|
|
896
|
-
console.warn(`ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}`);
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
if (hasRegisteredLang) {
|
|
900
|
-
return lowlight.highlight(lang, raw);
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
return lowlight.highlightAuto(raw);
|
|
904
|
-
}
|
|
905
|
-
},
|
|
906
|
-
});
|
|
907
|
-
Object.defineProperty(instance, "processAST", {
|
|
908
|
-
value: (ast) => {
|
|
909
|
-
return processAST(ast);
|
|
910
|
-
},
|
|
911
|
-
});
|
|
912
|
-
Object.defineProperty(instance, "hasRegisteredCurrentLang", {
|
|
913
|
-
value: (lang) => {
|
|
914
|
-
return lowlight.registered(lang);
|
|
915
|
-
},
|
|
916
|
-
});
|
|
917
|
-
const highlighter = instance;
|
|
918
|
-
|
|
919
|
-
var _Cache_keyArray, _Cache_maxLength;
|
|
920
|
-
class Cache extends Map {
|
|
921
|
-
constructor() {
|
|
922
|
-
super(...arguments);
|
|
923
|
-
_Cache_keyArray.set(this, []);
|
|
924
|
-
_Cache_maxLength.set(this, 30);
|
|
925
|
-
}
|
|
926
|
-
setMaxLength(length) {
|
|
927
|
-
__classPrivateFieldSet(this, _Cache_maxLength, length);
|
|
928
|
-
this._checkLength();
|
|
929
|
-
}
|
|
930
|
-
set(key, value) {
|
|
931
|
-
if (this.has(key))
|
|
932
|
-
return this;
|
|
933
|
-
__classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
|
|
934
|
-
this._checkLength();
|
|
935
|
-
return super.set(key, value);
|
|
936
|
-
}
|
|
937
|
-
_checkLength() {
|
|
938
|
-
while (__classPrivateFieldGet(this, _Cache_keyArray, "f").length > __classPrivateFieldGet(this, _Cache_maxLength, "f")) {
|
|
939
|
-
const key = __classPrivateFieldGet(this, _Cache_keyArray, "f").shift();
|
|
940
|
-
this.delete(key);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
_Cache_keyArray = new WeakMap(), _Cache_maxLength = new WeakMap();
|
|
945
|
-
|
|
946
|
-
var _File_instances, _File_doCheck;
|
|
947
|
-
const map = new Cache();
|
|
948
|
-
const devKey = "@git-diff-cache";
|
|
949
|
-
map.setMaxLength(50);
|
|
950
|
-
map.name = "@git-diff-view/core";
|
|
951
|
-
if (typeof globalThis !== "undefined") {
|
|
952
|
-
if (Array.isArray(globalThis[devKey])) {
|
|
953
|
-
globalThis[devKey] = globalThis[devKey].filter((i) => i !== map);
|
|
954
|
-
if (globalThis[devKey].length > 0) {
|
|
955
|
-
console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
|
|
956
|
-
}
|
|
957
|
-
globalThis[devKey].push(map);
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
globalThis[devKey] = [map];
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
class File {
|
|
964
|
-
static createInstance(data) {
|
|
965
|
-
const file = new File(data === null || data === void 0 ? void 0 : data.raw, data === null || data === void 0 ? void 0 : data.lang, data === null || data === void 0 ? void 0 : data.fileName);
|
|
966
|
-
file.ast = data === null || data === void 0 ? void 0 : data.ast;
|
|
967
|
-
file.rawFile = data === null || data === void 0 ? void 0 : data.rawFile;
|
|
968
|
-
file.hasDoRaw = data === null || data === void 0 ? void 0 : data.hasDoRaw;
|
|
969
|
-
file.rawLength = data === null || data === void 0 ? void 0 : data.rawLength;
|
|
970
|
-
file.syntaxFile = data === null || data === void 0 ? void 0 : data.syntaxFile;
|
|
971
|
-
file.hasDoSyntax = data === null || data === void 0 ? void 0 : data.hasDoSyntax;
|
|
972
|
-
file.syntaxLength = data === null || data === void 0 ? void 0 : data.syntaxLength;
|
|
973
|
-
file.highlighterName = data === null || data === void 0 ? void 0 : data.highlighterName;
|
|
974
|
-
file.maxLineNumber = data === null || data === void 0 ? void 0 : data.maxLineNumber;
|
|
975
|
-
return file;
|
|
976
|
-
}
|
|
977
|
-
constructor(raw, lang, fileName) {
|
|
978
|
-
_File_instances.add(this);
|
|
979
|
-
this.raw = raw;
|
|
980
|
-
this.lang = lang;
|
|
981
|
-
this.fileName = fileName;
|
|
982
|
-
this.rawFile = {};
|
|
983
|
-
this.hasDoRaw = false;
|
|
984
|
-
this.syntaxFile = {};
|
|
985
|
-
this.hasDoSyntax = false;
|
|
986
|
-
this.maxLineNumber = 0;
|
|
987
|
-
Object.defineProperty(this, "__v_skip", { value: true });
|
|
988
|
-
}
|
|
989
|
-
doSyntax({ registerHighlighter }) {
|
|
990
|
-
if (!this.raw || this.hasDoSyntax)
|
|
991
|
-
return;
|
|
992
|
-
const _highlighter = registerHighlighter || highlighter;
|
|
993
|
-
if (this.syntaxLength) {
|
|
994
|
-
console.error("current file already doSyntax before!");
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
if (this.rawLength > _highlighter.maxLineToIgnoreSyntax) {
|
|
998
|
-
console.warn(`ignore syntax for current file, because the rawLength is too long: ${this.rawLength}`);
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
|
-
this.ast = _highlighter.getAST(this.raw, this.fileName, this.lang);
|
|
1002
|
-
if (!this.ast)
|
|
1003
|
-
return;
|
|
1004
|
-
const { syntaxFileObject, syntaxFileLineNumber } = _highlighter.processAST(this.ast);
|
|
1005
|
-
this.syntaxFile = syntaxFileObject;
|
|
1006
|
-
this.syntaxLength = syntaxFileLineNumber;
|
|
1007
|
-
this.highlighterName = _highlighter.name;
|
|
1008
|
-
{
|
|
1009
|
-
__classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
|
|
1010
|
-
}
|
|
1011
|
-
this.hasDoSyntax = true;
|
|
1012
|
-
}
|
|
1013
|
-
doRaw() {
|
|
1014
|
-
if (!this.raw || this.hasDoRaw)
|
|
1015
|
-
return;
|
|
1016
|
-
const rawString = this.raw;
|
|
1017
|
-
const rawArray = rawString.split("\n");
|
|
1018
|
-
this.rawLength = rawArray.length;
|
|
1019
|
-
this.maxLineNumber = rawArray.length;
|
|
1020
|
-
this.rawFile = {};
|
|
1021
|
-
for (let i = 0; i < rawArray.length; i++) {
|
|
1022
|
-
this.rawFile[i + 1] = i < rawArray.length - 1 ? rawArray[i] + "\n" : rawArray[i];
|
|
1023
|
-
}
|
|
1024
|
-
// reduce 对于大数组性能很差
|
|
1025
|
-
// this.rawFile = rawArray.reduce(
|
|
1026
|
-
// (p, item, index) => ({
|
|
1027
|
-
// ...p,
|
|
1028
|
-
// [index + 1]: index < rawArray.length - 1 ? item + "\n" : item,
|
|
1029
|
-
// }),
|
|
1030
|
-
// {}
|
|
1031
|
-
// );
|
|
1032
|
-
this.hasDoRaw = true;
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
_File_instances = new WeakSet(), _File_doCheck = function _File_doCheck() {
|
|
1036
|
-
if (this.rawLength && this.syntaxLength) {
|
|
1037
|
-
if (this.rawLength !== this.syntaxLength) {
|
|
1038
|
-
console.warn("the rawLength not match for the syntaxLength");
|
|
1039
|
-
}
|
|
1040
|
-
Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
|
|
1041
|
-
if (value !== this.rawFile[lineNumber]) {
|
|
1042
|
-
console.log("some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber");
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
const getFile = (raw, lang, fileName) => {
|
|
1048
|
-
const key = raw + "--" + "0.0.13" + "--" + lang;
|
|
1049
|
-
if (map.has(key))
|
|
1050
|
-
return map.get(key);
|
|
1051
|
-
const file = new File(raw, lang, fileName);
|
|
1052
|
-
map.set(key, file);
|
|
1053
|
-
return file;
|
|
1054
|
-
};
|
|
1055
|
-
const _cacheMap = map;
|
|
1056
|
-
|
|
1057
|
-
var _DiffFile_instances, _DiffFile_oldFileResult, _DiffFile_newFileResult, _DiffFile_diffListResults, _DiffFile_diffLines, _DiffFile_oldFileDiffLines, _DiffFile_newFileDiffLines, _DiffFile_oldFileLines, _DiffFile_newFileLines, _DiffFile_oldFileSyntaxLines, _DiffFile_newFileSyntaxLines, _DiffFile_oldFilePlaceholderLines, _DiffFile_newFilePlaceholderLines, _DiffFile_splitLeftLines, _DiffFile_splitRightLines, _DiffFile_splitHunksLines, _DiffFile_unifiedLines, _DiffFile_unifiedHunksLines, _DiffFile_listeners, _DiffFile_hasInitRaw, _DiffFile_hasInitSyntax, _DiffFile_hasBuildSplit, _DiffFile_hasBuildUnified, _DiffFile_updateCount, _DiffFile_composeByDiff, _DiffFile_composeByMerge, _DiffFile_composeByFullMerge, _DiffFile_highlighterName, _DiffFile_id, _DiffFile_clonedInstance, _DiffFile_doDiff, _DiffFile_doFile, _DiffFile_composeRaw, _DiffFile_composeFile, _DiffFile_composeDiff, _DiffFile_composeSyntax, _DiffFile_getOldDiffLine, _DiffFile_getNewDiffLine, _DiffFile_getOldRawLine, _DiffFile_getNewRawLine;
|
|
1058
|
-
const composeLen = 40;
|
|
1059
|
-
const idSet = new Set();
|
|
1060
|
-
class DiffFile {
|
|
1061
|
-
static createInstance(data, bundle) {
|
|
1062
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1063
|
-
const instance = new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
|
|
1064
|
-
if (bundle) {
|
|
1065
|
-
if (bundle.isFullMerge) {
|
|
1066
|
-
instance._mergeFullBundle(bundle);
|
|
1067
|
-
}
|
|
1068
|
-
else {
|
|
1069
|
-
instance.mergeBundle(bundle);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
return instance;
|
|
1073
|
-
}
|
|
1074
|
-
constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
|
|
1075
|
-
_DiffFile_instances.add(this);
|
|
1076
|
-
this._oldFileName = _oldFileName;
|
|
1077
|
-
this._newFileName = _newFileName;
|
|
1078
|
-
this._diffList = _diffList;
|
|
1079
|
-
_DiffFile_oldFileResult.set(this, void 0);
|
|
1080
|
-
_DiffFile_newFileResult.set(this, void 0);
|
|
1081
|
-
_DiffFile_diffListResults.set(this, void 0);
|
|
1082
|
-
_DiffFile_diffLines.set(this, void 0);
|
|
1083
|
-
_DiffFile_oldFileDiffLines.set(this, void 0);
|
|
1084
|
-
_DiffFile_newFileDiffLines.set(this, void 0);
|
|
1085
|
-
_DiffFile_oldFileLines.set(this, void 0);
|
|
1086
|
-
_DiffFile_newFileLines.set(this, void 0);
|
|
1087
|
-
_DiffFile_oldFileSyntaxLines.set(this, void 0);
|
|
1088
|
-
_DiffFile_newFileSyntaxLines.set(this, void 0);
|
|
1089
|
-
_DiffFile_oldFilePlaceholderLines.set(this, void 0);
|
|
1090
|
-
_DiffFile_newFilePlaceholderLines.set(this, void 0);
|
|
1091
|
-
_DiffFile_splitLeftLines.set(this, []);
|
|
1092
|
-
_DiffFile_splitRightLines.set(this, []);
|
|
1093
|
-
_DiffFile_splitHunksLines.set(this, void 0);
|
|
1094
|
-
_DiffFile_unifiedLines.set(this, []);
|
|
1095
|
-
_DiffFile_unifiedHunksLines.set(this, void 0);
|
|
1096
|
-
_DiffFile_listeners.set(this, []);
|
|
1097
|
-
_DiffFile_hasInitRaw.set(this, false);
|
|
1098
|
-
_DiffFile_hasInitSyntax.set(this, false);
|
|
1099
|
-
_DiffFile_hasBuildSplit.set(this, false);
|
|
1100
|
-
_DiffFile_hasBuildUnified.set(this, false);
|
|
1101
|
-
_DiffFile_updateCount.set(this, 0);
|
|
1102
|
-
_DiffFile_composeByDiff.set(this, false);
|
|
1103
|
-
_DiffFile_composeByMerge.set(this, false);
|
|
1104
|
-
_DiffFile_composeByFullMerge.set(this, false);
|
|
1105
|
-
_DiffFile_highlighterName.set(this, void 0);
|
|
1106
|
-
this._version_ = "0.0.13";
|
|
1107
|
-
this._oldFileContent = "";
|
|
1108
|
-
this._oldFileLang = "";
|
|
1109
|
-
this._newFileContent = "";
|
|
1110
|
-
this._newFileLang = "";
|
|
1111
|
-
this.diffLineLength = 0;
|
|
1112
|
-
this.splitLineLength = 0;
|
|
1113
|
-
this.unifiedLineLength = 0;
|
|
1114
|
-
this.fileLineLength = 0;
|
|
1115
|
-
this.hasExpandSplitAll = false;
|
|
1116
|
-
this.hasExpandUnifiedAll = false;
|
|
1117
|
-
this.hasSomeLineCollapsed = false;
|
|
1118
|
-
_DiffFile_id.set(this, "");
|
|
1119
|
-
_DiffFile_clonedInstance.set(this, new Map());
|
|
1120
|
-
this.getSplitLeftLine = (index) => {
|
|
1121
|
-
return __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[index];
|
|
1122
|
-
};
|
|
1123
|
-
this.getSplitRightLine = (index) => {
|
|
1124
|
-
return __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[index];
|
|
1125
|
-
};
|
|
1126
|
-
this.getSplitHunkLine = (index) => {
|
|
1127
|
-
var _a;
|
|
1128
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1129
|
-
};
|
|
1130
|
-
this.onSplitHunkExpand = (dir, index, needTrigger = true) => {
|
|
1131
|
-
var _a, _b;
|
|
1132
|
-
const current = (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1133
|
-
if (!current || !current.splitInfo)
|
|
1134
|
-
return;
|
|
1135
|
-
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1136
|
-
return;
|
|
1137
|
-
if (dir === "all") {
|
|
1138
|
-
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
|
|
1139
|
-
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1140
|
-
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1141
|
-
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1142
|
-
leftLine.isHidden = false;
|
|
1143
|
-
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1144
|
-
rightLine.isHidden = false;
|
|
1145
|
-
}
|
|
1146
|
-
current.splitInfo = Object.assign(Object.assign(Object.assign({}, current.splitInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.splitInfo.endHiddenIndex });
|
|
1147
|
-
}
|
|
1148
|
-
else if (dir === "down") {
|
|
1149
|
-
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
|
|
1150
|
-
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1151
|
-
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1152
|
-
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1153
|
-
leftLine.isHidden = false;
|
|
1154
|
-
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1155
|
-
rightLine.isHidden = false;
|
|
1156
|
-
}
|
|
1157
|
-
if (current.isLast) {
|
|
1158
|
-
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen });
|
|
1159
|
-
}
|
|
1160
|
-
else {
|
|
1161
|
-
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}` });
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
else {
|
|
1165
|
-
if (current.isLast) {
|
|
1166
|
-
console.error("the last hunk can not expand up!");
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
for (let i = current.splitInfo.endHiddenIndex - composeLen; i < current.splitInfo.endHiddenIndex; i++) {
|
|
1170
|
-
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1171
|
-
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1172
|
-
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1173
|
-
leftLine.isHidden = false;
|
|
1174
|
-
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1175
|
-
rightLine.isHidden = false;
|
|
1176
|
-
}
|
|
1177
|
-
const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
|
|
1178
|
-
const oldLength = current.splitInfo.oldLength + composeLen;
|
|
1179
|
-
const newStartIndex = current.splitInfo.newStartIndex - composeLen;
|
|
1180
|
-
const newLength = current.splitInfo.newLength + composeLen;
|
|
1181
|
-
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen, oldStartIndex,
|
|
1182
|
-
oldLength,
|
|
1183
|
-
newStartIndex,
|
|
1184
|
-
newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
|
|
1185
|
-
(_b = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _b === void 0 ? true : delete _b[index];
|
|
1186
|
-
__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[current.splitInfo.endHiddenIndex] = current;
|
|
1187
|
-
}
|
|
1188
|
-
needTrigger && this.notifyAll();
|
|
1189
|
-
};
|
|
1190
|
-
this.getUnifiedLine = (index) => {
|
|
1191
|
-
return __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[index];
|
|
1192
|
-
};
|
|
1193
|
-
this.getUnifiedHunkLine = (index) => {
|
|
1194
|
-
var _a;
|
|
1195
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1196
|
-
};
|
|
1197
|
-
this.onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
|
|
1198
|
-
var _a, _b, _c;
|
|
1199
|
-
const current = (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1200
|
-
if (!current || !current.unifiedInfo)
|
|
1201
|
-
return;
|
|
1202
|
-
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1203
|
-
return;
|
|
1204
|
-
if (dir === "all") {
|
|
1205
|
-
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
|
|
1206
|
-
const unifiedLine = (_b = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")) === null || _b === void 0 ? void 0 : _b[i];
|
|
1207
|
-
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden) {
|
|
1208
|
-
unifiedLine.isHidden = false;
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
current.unifiedInfo = Object.assign(Object.assign(Object.assign({}, current.unifiedInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.unifiedInfo.endHiddenIndex });
|
|
1212
|
-
}
|
|
1213
|
-
else if (dir === "down") {
|
|
1214
|
-
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
|
|
1215
|
-
const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
|
|
1216
|
-
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1217
|
-
unifiedLine.isHidden = false;
|
|
1218
|
-
}
|
|
1219
|
-
if (current.isLast) {
|
|
1220
|
-
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen });
|
|
1221
|
-
}
|
|
1222
|
-
else {
|
|
1223
|
-
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}` });
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1227
|
-
if (current.isLast) {
|
|
1228
|
-
console.error("the last hunk can not expand up!");
|
|
1229
|
-
return;
|
|
1230
|
-
}
|
|
1231
|
-
for (let i = current.unifiedInfo.endHiddenIndex - composeLen; i < current.unifiedInfo.endHiddenIndex; i++) {
|
|
1232
|
-
const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
|
|
1233
|
-
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1234
|
-
unifiedLine.isHidden = false;
|
|
1235
|
-
}
|
|
1236
|
-
const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
|
|
1237
|
-
const oldLength = current.unifiedInfo.oldLength + composeLen;
|
|
1238
|
-
const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
|
|
1239
|
-
const newLength = current.unifiedInfo.newLength + composeLen;
|
|
1240
|
-
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen, oldStartIndex,
|
|
1241
|
-
oldLength,
|
|
1242
|
-
newStartIndex,
|
|
1243
|
-
newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
|
|
1244
|
-
(_c = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _c === void 0 ? true : delete _c[index];
|
|
1245
|
-
__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[current.unifiedInfo.endHiddenIndex] = current;
|
|
1246
|
-
}
|
|
1247
|
-
needTrigger && this.notifyAll();
|
|
1248
|
-
};
|
|
1249
|
-
this.onAllExpand = (mode) => {
|
|
1250
|
-
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1251
|
-
return;
|
|
1252
|
-
if (mode === "split") {
|
|
1253
|
-
Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
|
|
1254
|
-
this.onSplitHunkExpand("all", +key, false);
|
|
1255
|
-
});
|
|
1256
|
-
this.hasExpandSplitAll = true;
|
|
1257
|
-
}
|
|
1258
|
-
else {
|
|
1259
|
-
Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
|
|
1260
|
-
this.onUnifiedHunkExpand("all", +key, false);
|
|
1261
|
-
});
|
|
1262
|
-
this.hasExpandUnifiedAll = true;
|
|
1263
|
-
}
|
|
1264
|
-
this.notifyAll();
|
|
1265
|
-
};
|
|
1266
|
-
this.onAllCollapse = (mode) => {
|
|
1267
|
-
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1268
|
-
return;
|
|
1269
|
-
if (mode === "split") {
|
|
1270
|
-
Object.values(__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f") || {}).forEach((item) => {
|
|
1271
|
-
if (!item.isHidden && item._isHidden) {
|
|
1272
|
-
item.isHidden = item._isHidden;
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1275
|
-
Object.values(__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f") || {}).forEach((item) => {
|
|
1276
|
-
if (!item.isHidden && item._isHidden) {
|
|
1277
|
-
item.isHidden = item._isHidden;
|
|
1278
|
-
}
|
|
1279
|
-
});
|
|
1280
|
-
Object.values(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((item) => {
|
|
1281
|
-
if (!item.splitInfo)
|
|
1282
|
-
return;
|
|
1283
|
-
item.splitInfo = Object.assign(Object.assign({}, item.splitInfo), { oldStartIndex: item.splitInfo._oldStartIndex, oldLength: item.splitInfo._oldLength, newStartIndex: item.splitInfo._newStartIndex, newLength: item.splitInfo._newLength, startHiddenIndex: item.splitInfo._startHiddenIndex, endHiddenIndex: item.splitInfo._endHiddenIndex, plainText: item.splitInfo._plainText });
|
|
1284
|
-
});
|
|
1285
|
-
Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
|
|
1286
|
-
const item = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
|
|
1287
|
-
if (!item.splitInfo)
|
|
1288
|
-
return;
|
|
1289
|
-
if (item.splitInfo.endHiddenIndex !== +key) {
|
|
1290
|
-
delete __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
|
|
1291
|
-
__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[item.splitInfo.endHiddenIndex] = item;
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
|
-
this.hasExpandSplitAll = false;
|
|
1295
|
-
}
|
|
1296
|
-
else {
|
|
1297
|
-
Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f") || {}).forEach((item) => {
|
|
1298
|
-
if (!item.isHidden && item._isHidden) {
|
|
1299
|
-
item.isHidden = item._isHidden;
|
|
1300
|
-
}
|
|
1301
|
-
});
|
|
1302
|
-
Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((item) => {
|
|
1303
|
-
if (!item.unifiedInfo)
|
|
1304
|
-
return;
|
|
1305
|
-
item.unifiedInfo = Object.assign(Object.assign({}, item.unifiedInfo), { oldStartIndex: item.unifiedInfo._oldStartIndex, oldLength: item.unifiedInfo._oldLength, newStartIndex: item.unifiedInfo._newStartIndex, newLength: item.unifiedInfo._newLength, startHiddenIndex: item.unifiedInfo._startHiddenIndex, endHiddenIndex: item.unifiedInfo._endHiddenIndex, plainText: item.unifiedInfo._plainText });
|
|
1306
|
-
});
|
|
1307
|
-
Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
|
|
1308
|
-
const item = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
|
|
1309
|
-
if (!item.unifiedInfo)
|
|
1310
|
-
return;
|
|
1311
|
-
if (item.unifiedInfo.endHiddenIndex !== +key) {
|
|
1312
|
-
delete __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
|
|
1313
|
-
__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[item.unifiedInfo.endHiddenIndex] = item;
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
this.hasExpandUnifiedAll = false;
|
|
1317
|
-
}
|
|
1318
|
-
this.notifyAll();
|
|
1319
|
-
};
|
|
1320
|
-
this.getOldSyntaxLine = (lineNumber) => {
|
|
1321
|
-
var _a;
|
|
1322
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1323
|
-
};
|
|
1324
|
-
this.getNewSyntaxLine = (lineNumber) => {
|
|
1325
|
-
var _a;
|
|
1326
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1327
|
-
};
|
|
1328
|
-
this.subscribe = (listener) => {
|
|
1329
|
-
__classPrivateFieldGet(this, _DiffFile_listeners, "f").push(listener);
|
|
1330
|
-
return () => {
|
|
1331
|
-
__classPrivateFieldGet(this, _DiffFile_listeners, "f").filter((i) => i !== listener);
|
|
1332
|
-
};
|
|
1333
|
-
};
|
|
1334
|
-
this.notifyAll = (skipSyncExternal) => {
|
|
1335
|
-
var _a;
|
|
1336
|
-
__classPrivateFieldSet(this, _DiffFile_updateCount, (_a = __classPrivateFieldGet(this, _DiffFile_updateCount, "f"), _a++, _a));
|
|
1337
|
-
__classPrivateFieldGet(this, _DiffFile_listeners, "f").forEach((f) => {
|
|
1338
|
-
if (skipSyncExternal && f.isSyncExternal) {
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
f();
|
|
1342
|
-
});
|
|
1343
|
-
// support update from outside instance
|
|
1344
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, instance) => {
|
|
1345
|
-
instance.notifyAll(true);
|
|
1346
|
-
});
|
|
1347
|
-
};
|
|
1348
|
-
this.getUpdateCount = () => __classPrivateFieldGet(this, _DiffFile_updateCount, "f");
|
|
1349
|
-
this.getExpandEnabled = () => !__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1350
|
-
this.getBundle = () => {
|
|
1351
|
-
// common
|
|
1352
|
-
const hasInitRaw = __classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f");
|
|
1353
|
-
const hasInitSyntax = __classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f");
|
|
1354
|
-
const hasBuildSplit = __classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f");
|
|
1355
|
-
const hasBuildUnified = __classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f");
|
|
1356
|
-
const oldFileLines = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f");
|
|
1357
|
-
const oldFileDiffLines = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f");
|
|
1358
|
-
const oldFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f");
|
|
1359
|
-
const oldFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f");
|
|
1360
|
-
const newFileLines = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f");
|
|
1361
|
-
const newFileDiffLines = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f");
|
|
1362
|
-
const newFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f");
|
|
1363
|
-
const newFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f");
|
|
1364
|
-
const splitLineLength = this.splitLineLength;
|
|
1365
|
-
const unifiedLineLength = this.unifiedLineLength;
|
|
1366
|
-
const fileLineLength = this.fileLineLength;
|
|
1367
|
-
const composeByDiff = __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1368
|
-
const highlighterName = __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
|
|
1369
|
-
const hasSomeLineCollapsed = this.hasSomeLineCollapsed;
|
|
1370
|
-
// split
|
|
1371
|
-
const splitLeftLines = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f");
|
|
1372
|
-
const splitRightLines = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f");
|
|
1373
|
-
const splitHunkLines = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f");
|
|
1374
|
-
// unified
|
|
1375
|
-
const unifiedLines = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f");
|
|
1376
|
-
const unifiedHunkLines = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f");
|
|
1377
|
-
const version = this._version_;
|
|
1378
|
-
return {
|
|
1379
|
-
hasInitRaw,
|
|
1380
|
-
hasInitSyntax,
|
|
1381
|
-
hasBuildSplit,
|
|
1382
|
-
hasBuildUnified,
|
|
1383
|
-
oldFileLines,
|
|
1384
|
-
oldFileDiffLines,
|
|
1385
|
-
oldFileSyntaxLines,
|
|
1386
|
-
oldFilePlaceholderLines,
|
|
1387
|
-
newFileLines,
|
|
1388
|
-
newFileDiffLines,
|
|
1389
|
-
newFileSyntaxLines,
|
|
1390
|
-
newFilePlaceholderLines,
|
|
1391
|
-
splitLineLength,
|
|
1392
|
-
unifiedLineLength,
|
|
1393
|
-
fileLineLength,
|
|
1394
|
-
splitLeftLines,
|
|
1395
|
-
splitRightLines,
|
|
1396
|
-
splitHunkLines,
|
|
1397
|
-
unifiedLines,
|
|
1398
|
-
unifiedHunkLines,
|
|
1399
|
-
highlighterName,
|
|
1400
|
-
composeByDiff,
|
|
1401
|
-
hasSomeLineCollapsed,
|
|
1402
|
-
version,
|
|
1403
|
-
isFullMerge: false,
|
|
1404
|
-
};
|
|
1405
|
-
};
|
|
1406
|
-
this.mergeBundle = (data) => {
|
|
1407
|
-
__classPrivateFieldSet(this, _DiffFile_hasInitRaw, data.hasInitRaw);
|
|
1408
|
-
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, data.hasInitSyntax);
|
|
1409
|
-
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, data.hasBuildSplit);
|
|
1410
|
-
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, data.hasBuildUnified);
|
|
1411
|
-
__classPrivateFieldSet(this, _DiffFile_composeByDiff, data.composeByDiff);
|
|
1412
|
-
__classPrivateFieldSet(this, _DiffFile_highlighterName, data.highlighterName);
|
|
1413
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileLines, data.oldFileLines);
|
|
1414
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, data.oldFileDiffLines);
|
|
1415
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, data.oldFileSyntaxLines);
|
|
1416
|
-
__classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, data.oldFilePlaceholderLines);
|
|
1417
|
-
__classPrivateFieldSet(this, _DiffFile_newFileLines, data.newFileLines);
|
|
1418
|
-
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, data.newFileDiffLines);
|
|
1419
|
-
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, data.newFileSyntaxLines);
|
|
1420
|
-
__classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, data.newFilePlaceholderLines);
|
|
1421
|
-
this.splitLineLength = data.splitLineLength;
|
|
1422
|
-
this.unifiedLineLength = data.unifiedLineLength;
|
|
1423
|
-
this.fileLineLength = data.fileLineLength;
|
|
1424
|
-
this.hasSomeLineCollapsed = data.hasSomeLineCollapsed;
|
|
1425
|
-
__classPrivateFieldSet(this, _DiffFile_splitLeftLines, data.splitLeftLines);
|
|
1426
|
-
__classPrivateFieldSet(this, _DiffFile_splitRightLines, data.splitRightLines);
|
|
1427
|
-
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, data.splitHunkLines);
|
|
1428
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedLines, data.unifiedLines);
|
|
1429
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, data.unifiedHunkLines);
|
|
1430
|
-
// mark this instance as a merged instance
|
|
1431
|
-
__classPrivateFieldSet(this, _DiffFile_composeByMerge, true);
|
|
1432
|
-
if (this._version_ !== data.version) {
|
|
1433
|
-
console.error("the version of the `diffInstance` is not match, some error may happen!");
|
|
1434
|
-
}
|
|
1435
|
-
this.notifyAll();
|
|
1436
|
-
};
|
|
1437
|
-
this._getHighlighterName = () => __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
|
|
1438
|
-
this._getIsPureDiffRender = () => __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1439
|
-
this._addClonedInstance = (instance) => {
|
|
1440
|
-
const updateFunc = () => {
|
|
1441
|
-
this._notifyOthers(instance);
|
|
1442
|
-
};
|
|
1443
|
-
updateFunc.isSyncExternal = true;
|
|
1444
|
-
const unsubscribe = instance.subscribe(updateFunc);
|
|
1445
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").set(instance, unsubscribe);
|
|
1446
|
-
};
|
|
1447
|
-
this._notifyOthers = (instance) => {
|
|
1448
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, i) => {
|
|
1449
|
-
if (i !== instance) {
|
|
1450
|
-
i.notifyAll(true);
|
|
1451
|
-
}
|
|
1452
|
-
});
|
|
1453
|
-
};
|
|
1454
|
-
this._delClonedInstance = (instance) => {
|
|
1455
|
-
const unsubscribe = __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").get(instance);
|
|
1456
|
-
unsubscribe && unsubscribe();
|
|
1457
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").delete(instance);
|
|
1458
|
-
};
|
|
1459
|
-
this._getFullBundle = () => {
|
|
1460
|
-
const bundle = this.getBundle();
|
|
1461
|
-
const oldFileResult = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f");
|
|
1462
|
-
const newFileResult = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f");
|
|
1463
|
-
const diffLines = __classPrivateFieldGet(this, _DiffFile_diffLines, "f");
|
|
1464
|
-
const diffListResults = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f");
|
|
1465
|
-
return Object.assign(Object.assign({}, bundle), { oldFileResult,
|
|
1466
|
-
newFileResult,
|
|
1467
|
-
diffLines,
|
|
1468
|
-
diffListResults,
|
|
1469
|
-
// get current instance is a fullMerge instance or not
|
|
1470
|
-
isFullMerge: __classPrivateFieldGet(this, _DiffFile_composeByMerge, "f") ? __classPrivateFieldGet(this, _DiffFile_composeByFullMerge, "f") : true });
|
|
1471
|
-
};
|
|
1472
|
-
this._mergeFullBundle = (data) => {
|
|
1473
|
-
this.mergeBundle(data);
|
|
1474
|
-
try {
|
|
1475
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileResult, File.createInstance(data.oldFileResult), "f");
|
|
1476
|
-
__classPrivateFieldSet(this, _DiffFile_newFileResult, File.createInstance(data.newFileResult), "f");
|
|
1477
|
-
__classPrivateFieldSet(this, _DiffFile_diffLines, data.diffLines, "f");
|
|
1478
|
-
__classPrivateFieldSet(this, _DiffFile_diffListResults, data.diffListResults, "f");
|
|
1479
|
-
__classPrivateFieldSet(this, _DiffFile_composeByFullMerge, data.isFullMerge, "f");
|
|
1480
|
-
}
|
|
1481
|
-
catch (_a) {
|
|
1482
|
-
}
|
|
1483
|
-
};
|
|
1484
|
-
this._destroy = () => {
|
|
1485
|
-
this.clearId();
|
|
1486
|
-
__classPrivateFieldGet(this, _DiffFile_listeners, "f").splice(0, __classPrivateFieldGet(this, _DiffFile_listeners, "f").length);
|
|
1487
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((v) => v());
|
|
1488
|
-
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").clear();
|
|
1489
|
-
};
|
|
1490
|
-
this.clear = () => {
|
|
1491
|
-
this._destroy();
|
|
1492
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileResult, null);
|
|
1493
|
-
__classPrivateFieldSet(this, _DiffFile_newFileResult, null);
|
|
1494
|
-
__classPrivateFieldSet(this, _DiffFile_diffLines, null);
|
|
1495
|
-
__classPrivateFieldSet(this, _DiffFile_diffListResults, null);
|
|
1496
|
-
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, null);
|
|
1497
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, null);
|
|
1498
|
-
__classPrivateFieldSet(this, _DiffFile_newFileLines, null);
|
|
1499
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileLines, null);
|
|
1500
|
-
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, null);
|
|
1501
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, null);
|
|
1502
|
-
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, null);
|
|
1503
|
-
__classPrivateFieldSet(this, _DiffFile_splitLeftLines, null);
|
|
1504
|
-
__classPrivateFieldSet(this, _DiffFile_splitRightLines, null);
|
|
1505
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, null);
|
|
1506
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedLines, null);
|
|
1507
|
-
};
|
|
1508
|
-
Object.defineProperty(this, "__v_skip", { value: true });
|
|
1509
|
-
let oldContent = _oldFileContent;
|
|
1510
|
-
let newContent = _newFileContent;
|
|
1511
|
-
const diffList = Array.from(new Set(_diffList));
|
|
1512
|
-
Object.defineProperties(this, {
|
|
1513
|
-
_oldFileName: { get: () => _oldFileName },
|
|
1514
|
-
_newFileName: { get: () => _newFileName },
|
|
1515
|
-
_oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
|
|
1516
|
-
_newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
|
|
1517
|
-
_oldFileContent: {
|
|
1518
|
-
get: () => oldContent,
|
|
1519
|
-
set: (v) => (oldContent = v),
|
|
1520
|
-
},
|
|
1521
|
-
_newFileContent: {
|
|
1522
|
-
get: () => newContent,
|
|
1523
|
-
set: (v) => (newContent = v),
|
|
1524
|
-
},
|
|
1525
|
-
_diffList: { get: () => diffList },
|
|
1526
|
-
});
|
|
1527
|
-
this.initId();
|
|
1528
|
-
}
|
|
1529
|
-
initId() {
|
|
1530
|
-
let id = "--" + Math.random().toString().slice(2);
|
|
1531
|
-
while (idSet.has(id)) {
|
|
1532
|
-
id = "--" + Math.random().toString().slice(2);
|
|
1533
|
-
}
|
|
1534
|
-
idSet.add(id);
|
|
1535
|
-
__classPrivateFieldSet(this, _DiffFile_id, id);
|
|
1536
|
-
}
|
|
1537
|
-
getId() {
|
|
1538
|
-
return __classPrivateFieldGet(this, _DiffFile_id, "f");
|
|
1539
|
-
}
|
|
1540
|
-
clearId() {
|
|
1541
|
-
idSet.delete(__classPrivateFieldGet(this, _DiffFile_id, "f"));
|
|
1542
|
-
}
|
|
1543
|
-
initRaw() {
|
|
1544
|
-
if (__classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f"))
|
|
1545
|
-
return;
|
|
1546
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doDiff).call(this);
|
|
1547
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeDiff).call(this);
|
|
1548
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doFile).call(this);
|
|
1549
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
|
|
1550
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeFile).call(this);
|
|
1551
|
-
__classPrivateFieldSet(this, _DiffFile_hasInitRaw, true);
|
|
1552
|
-
}
|
|
1553
|
-
initSyntax({ registerHighlighter } = {}) {
|
|
1554
|
-
var _a, _b;
|
|
1555
|
-
if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
|
|
1556
|
-
return;
|
|
1557
|
-
if (__classPrivateFieldGet(this, _DiffFile_composeByMerge, "f") && !__classPrivateFieldGet(this, _DiffFile_composeByFullMerge, "f")) {
|
|
1558
|
-
console.error(`this instance can not do syntax because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'`);
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter });
|
|
1562
|
-
__classPrivateFieldSet(this, _DiffFile_highlighterName, ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.highlighterName) || ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.highlighterName) || __classPrivateFieldGet(this, _DiffFile_highlighterName, "f"));
|
|
1563
|
-
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true);
|
|
1564
|
-
}
|
|
1565
|
-
init() {
|
|
1566
|
-
this.initRaw();
|
|
1567
|
-
this.initSyntax();
|
|
1568
|
-
}
|
|
1569
|
-
buildSplitDiffLines() {
|
|
1570
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1571
|
-
if (__classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f"))
|
|
1572
|
-
return;
|
|
1573
|
-
let oldFileLineNumber = 1;
|
|
1574
|
-
let newFileLineNumber = 1;
|
|
1575
|
-
let prevIsHidden = false;
|
|
1576
|
-
let hideStart = Infinity;
|
|
1577
|
-
const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
|
|
1578
|
-
const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
|
|
1579
|
-
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
1580
|
-
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
|
|
1581
|
-
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
|
|
1582
|
-
const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
|
|
1583
|
-
const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
|
|
1584
|
-
const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
|
|
1585
|
-
const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
|
|
1586
|
-
const len = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
|
|
1587
|
-
const isHidden = !oldDiffLine && !newDiffLine;
|
|
1588
|
-
if (oldDiffLine && !newDiffLine) {
|
|
1589
|
-
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1590
|
-
newFileLineNumber++;
|
|
1591
|
-
continue;
|
|
1592
|
-
}
|
|
1593
|
-
if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
|
|
1594
|
-
newFileLineNumber++;
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
if (newDiffLine && !oldDiffLine) {
|
|
1598
|
-
if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
|
|
1599
|
-
oldFileLineNumber++;
|
|
1600
|
-
continue;
|
|
1601
|
-
}
|
|
1602
|
-
if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
|
|
1603
|
-
oldFileLineNumber++;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
if (!oldDiffLine && !oldRawLine && !newDiffLine && !newRawLine)
|
|
1607
|
-
break;
|
|
1608
|
-
if (!oldDiffLine && !newDiffLine) {
|
|
1609
|
-
if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
|
|
1610
|
-
oldFileLineNumber++;
|
|
1611
|
-
newFileLineNumber++;
|
|
1612
|
-
continue;
|
|
1613
|
-
}
|
|
1614
|
-
if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
|
|
1615
|
-
newFileLineNumber++;
|
|
1616
|
-
continue;
|
|
1617
|
-
}
|
|
1618
|
-
if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
|
|
1619
|
-
oldFileLineNumber++;
|
|
1620
|
-
continue;
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
if ((oldLineHasChange && newLineHasChange) || (!oldLineHasChange && !newLineHasChange)) {
|
|
1624
|
-
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
1625
|
-
lineNumber: oldFileLineNumber++,
|
|
1626
|
-
value: oldRawLine,
|
|
1627
|
-
diff: oldDiffLine,
|
|
1628
|
-
isHidden,
|
|
1629
|
-
_isHidden: isHidden,
|
|
1630
|
-
});
|
|
1631
|
-
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
1632
|
-
lineNumber: newFileLineNumber++,
|
|
1633
|
-
value: newRawLine,
|
|
1634
|
-
diff: newDiffLine,
|
|
1635
|
-
isHidden,
|
|
1636
|
-
_isHidden: isHidden,
|
|
1637
|
-
});
|
|
1638
|
-
}
|
|
1639
|
-
else if (oldLineHasChange) {
|
|
1640
|
-
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
1641
|
-
lineNumber: oldFileLineNumber++,
|
|
1642
|
-
value: oldRawLine,
|
|
1643
|
-
diff: oldDiffLine,
|
|
1644
|
-
isHidden,
|
|
1645
|
-
_isHidden: isHidden,
|
|
1646
|
-
});
|
|
1647
|
-
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({});
|
|
1648
|
-
}
|
|
1649
|
-
else if (newLineHasChange) {
|
|
1650
|
-
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({});
|
|
1651
|
-
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
1652
|
-
lineNumber: newFileLineNumber++,
|
|
1653
|
-
value: newRawLine,
|
|
1654
|
-
diff: newDiffLine,
|
|
1655
|
-
isHidden,
|
|
1656
|
-
_isHidden: isHidden,
|
|
1657
|
-
});
|
|
1658
|
-
}
|
|
1659
|
-
if (!prevIsHidden && isHidden) {
|
|
1660
|
-
hideStart = len;
|
|
1661
|
-
}
|
|
1662
|
-
if (isHidden) {
|
|
1663
|
-
this.hasSomeLineCollapsed = true;
|
|
1664
|
-
}
|
|
1665
|
-
prevIsHidden = isHidden;
|
|
1666
|
-
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
1667
|
-
const current = newDiffLine;
|
|
1668
|
-
const previous = newDiffLine.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
|
|
1669
|
-
if (previous && previous.type === exports.DiffLineType.Hunk) {
|
|
1670
|
-
const typedPrevious = previous;
|
|
1671
|
-
if (Number.isFinite(hideStart)) {
|
|
1672
|
-
typedPrevious.splitInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
1673
|
-
hideStart = Infinity;
|
|
1674
|
-
}
|
|
1675
|
-
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [len]: typedPrevious }));
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
// have last hunk
|
|
1680
|
-
if (Number.isFinite(hideStart)) {
|
|
1681
|
-
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
1682
|
-
const lastHunk = lastDiff;
|
|
1683
|
-
lastHunk.isLast = true;
|
|
1684
|
-
lastHunk.splitInfo = {
|
|
1685
|
-
startHiddenIndex: hideStart,
|
|
1686
|
-
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
1687
|
-
_startHiddenIndex: hideStart,
|
|
1688
|
-
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
1689
|
-
// just for placeholder
|
|
1690
|
-
plainText: "",
|
|
1691
|
-
oldStartIndex: 0,
|
|
1692
|
-
newStartIndex: 0,
|
|
1693
|
-
oldLength: 0,
|
|
1694
|
-
newLength: 0,
|
|
1695
|
-
_plainText: "",
|
|
1696
|
-
_oldStartIndex: 0,
|
|
1697
|
-
_newStartIndex: 0,
|
|
1698
|
-
_oldLength: 0,
|
|
1699
|
-
_newLength: 0,
|
|
1700
|
-
};
|
|
1701
|
-
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length]: lastHunk }));
|
|
1702
|
-
hideStart = Infinity;
|
|
1703
|
-
}
|
|
1704
|
-
this.splitLineLength = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
|
|
1705
|
-
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, true);
|
|
1706
|
-
this.notifyAll();
|
|
1707
|
-
}
|
|
1708
|
-
buildUnifiedDiffLines() {
|
|
1709
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1710
|
-
if (__classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f"))
|
|
1711
|
-
return;
|
|
1712
|
-
let oldFileLineNumber = 1;
|
|
1713
|
-
let newFileLineNumber = 1;
|
|
1714
|
-
let prevIsHidden = false;
|
|
1715
|
-
let hideStart = Infinity;
|
|
1716
|
-
const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
|
|
1717
|
-
const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
|
|
1718
|
-
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
1719
|
-
const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
|
|
1720
|
-
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
|
|
1721
|
-
const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
|
|
1722
|
-
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
|
|
1723
|
-
const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
|
|
1724
|
-
const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
|
|
1725
|
-
const len = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
|
|
1726
|
-
const isHidden = !oldDiffLine && !newDiffLine;
|
|
1727
|
-
if (oldDiffLine && !newDiffLine) {
|
|
1728
|
-
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1729
|
-
newFileLineNumber++;
|
|
1730
|
-
continue;
|
|
1731
|
-
}
|
|
1732
|
-
if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
|
|
1733
|
-
newFileLineNumber++;
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
if (newDiffLine && !oldDiffLine) {
|
|
1737
|
-
if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
|
|
1738
|
-
oldFileLineNumber++;
|
|
1739
|
-
continue;
|
|
1740
|
-
}
|
|
1741
|
-
if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
|
|
1742
|
-
oldFileLineNumber++;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
if (!oldRawLine && !newRawLine && !newDiffLine && !oldDiffLine)
|
|
1746
|
-
break;
|
|
1747
|
-
if (!oldDiffLine && !newDiffLine) {
|
|
1748
|
-
if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
|
|
1749
|
-
oldFileLineNumber++;
|
|
1750
|
-
newFileLineNumber++;
|
|
1751
|
-
continue;
|
|
1752
|
-
}
|
|
1753
|
-
if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
|
|
1754
|
-
newFileLineNumber++;
|
|
1755
|
-
continue;
|
|
1756
|
-
}
|
|
1757
|
-
if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
|
|
1758
|
-
oldFileLineNumber++;
|
|
1759
|
-
continue;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
if (!oldLineHasChange && !newLineHasChange) {
|
|
1763
|
-
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
1764
|
-
oldLineNumber: oldFileLineNumber++,
|
|
1765
|
-
newLineNumber: newFileLineNumber++,
|
|
1766
|
-
value: newRawLine,
|
|
1767
|
-
diff: newDiffLine,
|
|
1768
|
-
isHidden,
|
|
1769
|
-
_isHidden: isHidden,
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
else if (oldLineHasChange) {
|
|
1773
|
-
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
1774
|
-
oldLineNumber: oldFileLineNumber++,
|
|
1775
|
-
value: oldRawLine,
|
|
1776
|
-
diff: oldDiffLine,
|
|
1777
|
-
isHidden,
|
|
1778
|
-
_isHidden: isHidden,
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
else if (newLineHasChange) {
|
|
1782
|
-
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
1783
|
-
newLineNumber: newFileLineNumber++,
|
|
1784
|
-
value: newRawLine,
|
|
1785
|
-
diff: newDiffLine,
|
|
1786
|
-
isHidden,
|
|
1787
|
-
_isHidden: isHidden,
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
if (!prevIsHidden && isHidden) {
|
|
1791
|
-
hideStart = len;
|
|
1792
|
-
}
|
|
1793
|
-
if (isHidden) {
|
|
1794
|
-
this.hasSomeLineCollapsed = true;
|
|
1795
|
-
}
|
|
1796
|
-
prevIsHidden = isHidden;
|
|
1797
|
-
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
1798
|
-
const current = newDiffLine;
|
|
1799
|
-
const previous = current.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
|
|
1800
|
-
if (previous && previous.type === exports.DiffLineType.Hunk) {
|
|
1801
|
-
const typedPrevious = previous;
|
|
1802
|
-
if (Number.isFinite(hideStart)) {
|
|
1803
|
-
typedPrevious.unifiedInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
1804
|
-
hideStart = Infinity;
|
|
1805
|
-
}
|
|
1806
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [len]: typedPrevious }));
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
// have last hunk
|
|
1811
|
-
if (Number.isFinite(hideStart)) {
|
|
1812
|
-
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
1813
|
-
const lastHunk = lastDiff;
|
|
1814
|
-
lastHunk.isLast = true;
|
|
1815
|
-
lastHunk.unifiedInfo = {
|
|
1816
|
-
startHiddenIndex: hideStart,
|
|
1817
|
-
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
1818
|
-
_startHiddenIndex: hideStart,
|
|
1819
|
-
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
1820
|
-
// just for placeholder
|
|
1821
|
-
plainText: "",
|
|
1822
|
-
oldStartIndex: 0,
|
|
1823
|
-
newStartIndex: 0,
|
|
1824
|
-
oldLength: 0,
|
|
1825
|
-
newLength: 0,
|
|
1826
|
-
_plainText: "",
|
|
1827
|
-
_oldStartIndex: 0,
|
|
1828
|
-
_newStartIndex: 0,
|
|
1829
|
-
_oldLength: 0,
|
|
1830
|
-
_newLength: 0,
|
|
1831
|
-
};
|
|
1832
|
-
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length]: lastHunk }));
|
|
1833
|
-
hideStart = Infinity;
|
|
1834
|
-
}
|
|
1835
|
-
this.unifiedLineLength = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
|
|
1836
|
-
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, true);
|
|
1837
|
-
this.notifyAll();
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
_DiffFile_oldFileResult = new WeakMap(), _DiffFile_newFileResult = new WeakMap(), _DiffFile_diffListResults = new WeakMap(), _DiffFile_diffLines = new WeakMap(), _DiffFile_oldFileDiffLines = new WeakMap(), _DiffFile_newFileDiffLines = new WeakMap(), _DiffFile_oldFileLines = new WeakMap(), _DiffFile_newFileLines = new WeakMap(), _DiffFile_oldFileSyntaxLines = new WeakMap(), _DiffFile_newFileSyntaxLines = new WeakMap(), _DiffFile_oldFilePlaceholderLines = new WeakMap(), _DiffFile_newFilePlaceholderLines = new WeakMap(), _DiffFile_splitLeftLines = new WeakMap(), _DiffFile_splitRightLines = new WeakMap(), _DiffFile_splitHunksLines = new WeakMap(), _DiffFile_unifiedLines = new WeakMap(), _DiffFile_unifiedHunksLines = new WeakMap(), _DiffFile_listeners = new WeakMap(), _DiffFile_hasInitRaw = new WeakMap(), _DiffFile_hasInitSyntax = new WeakMap(), _DiffFile_hasBuildSplit = new WeakMap(), _DiffFile_hasBuildUnified = new WeakMap(), _DiffFile_updateCount = new WeakMap(), _DiffFile_composeByDiff = new WeakMap(), _DiffFile_composeByMerge = new WeakMap(), _DiffFile_composeByFullMerge = new WeakMap(), _DiffFile_highlighterName = new WeakMap(), _DiffFile_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
|
|
1841
|
-
if (!this._diffList)
|
|
1842
|
-
return;
|
|
1843
|
-
__classPrivateFieldSet(this, _DiffFile_diffListResults, this._diffList.map((s) => parseInstance.parse(s)));
|
|
1844
|
-
}, _DiffFile_doFile = function _DiffFile_doFile() {
|
|
1845
|
-
if (!this._oldFileContent && !this._newFileContent)
|
|
1846
|
-
return;
|
|
1847
|
-
if (this._oldFileContent) {
|
|
1848
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName));
|
|
1849
|
-
this.fileLineLength = Math.max(this.fileLineLength, __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber);
|
|
1850
|
-
}
|
|
1851
|
-
if (this._newFileContent) {
|
|
1852
|
-
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName));
|
|
1853
|
-
this.fileLineLength = Math.max(this.fileLineLength, __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber);
|
|
1854
|
-
}
|
|
1855
|
-
}, _DiffFile_composeRaw = function _DiffFile_composeRaw() {
|
|
1856
|
-
var _a, _b, _c, _d;
|
|
1857
|
-
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doRaw();
|
|
1858
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.rawFile);
|
|
1859
|
-
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doRaw();
|
|
1860
|
-
__classPrivateFieldSet(this, _DiffFile_newFileLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.rawFile);
|
|
1861
|
-
}, _DiffFile_composeFile = function _DiffFile_composeFile() {
|
|
1862
|
-
if (this._oldFileContent && this._newFileContent)
|
|
1863
|
-
return;
|
|
1864
|
-
const oldFilePlaceholderLines = {};
|
|
1865
|
-
const newFilePlaceholderLines = {};
|
|
1866
|
-
// all of the file content not exist, try to use diff result to compose
|
|
1867
|
-
if (!this._oldFileContent && !this._newFileContent) {
|
|
1868
|
-
let newLineNumber = 1;
|
|
1869
|
-
let oldLineNumber = 1;
|
|
1870
|
-
let oldFileContent = "";
|
|
1871
|
-
let newFileContent = "";
|
|
1872
|
-
let hasSymbolChanged = false;
|
|
1873
|
-
while (oldLineNumber <= this.diffLineLength || newLineNumber <= this.diffLineLength) {
|
|
1874
|
-
const oldIndex = oldLineNumber++;
|
|
1875
|
-
const newIndex = newLineNumber++;
|
|
1876
|
-
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldIndex);
|
|
1877
|
-
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newIndex);
|
|
1878
|
-
if (oldDiffLine) {
|
|
1879
|
-
oldFileContent += oldDiffLine.text;
|
|
1880
|
-
}
|
|
1881
|
-
else {
|
|
1882
|
-
// empty line for placeholder
|
|
1883
|
-
oldFileContent += "\n";
|
|
1884
|
-
oldFilePlaceholderLines[oldIndex] = true;
|
|
1885
|
-
}
|
|
1886
|
-
if (newDiffLine) {
|
|
1887
|
-
newFileContent += newDiffLine.text;
|
|
1888
|
-
}
|
|
1889
|
-
else {
|
|
1890
|
-
// empty line for placeholder
|
|
1891
|
-
newFileContent += "\n";
|
|
1892
|
-
newFilePlaceholderLines[newIndex] = true;
|
|
1893
|
-
}
|
|
1894
|
-
if (!hasSymbolChanged && oldDiffLine && newDiffLine) {
|
|
1895
|
-
hasSymbolChanged = hasSymbolChanged || oldDiffLine.noTrailingNewLine !== newDiffLine.noTrailingNewLine;
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
if (!hasSymbolChanged && oldFileContent === newFileContent)
|
|
1899
|
-
return;
|
|
1900
|
-
this._oldFileContent = oldFileContent;
|
|
1901
|
-
this._newFileContent = newFileContent;
|
|
1902
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName));
|
|
1903
|
-
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName));
|
|
1904
|
-
__classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, oldFilePlaceholderLines);
|
|
1905
|
-
__classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, newFilePlaceholderLines);
|
|
1906
|
-
this.fileLineLength = Math.max(this.fileLineLength, __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber, __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber);
|
|
1907
|
-
// all of the file just compose by diff, so we can not do the expand action
|
|
1908
|
-
__classPrivateFieldSet(this, _DiffFile_composeByDiff, true);
|
|
1909
|
-
}
|
|
1910
|
-
else if (__classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) {
|
|
1911
|
-
let newLineNumber = 1;
|
|
1912
|
-
let oldLineNumber = 1;
|
|
1913
|
-
let newFileContent = "";
|
|
1914
|
-
let hasSymbolChanged = false;
|
|
1915
|
-
while (oldLineNumber <= __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber) {
|
|
1916
|
-
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber++);
|
|
1917
|
-
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber);
|
|
1918
|
-
if (newDiffLine) {
|
|
1919
|
-
newFileContent += newDiffLine.text;
|
|
1920
|
-
oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
|
|
1921
|
-
}
|
|
1922
|
-
else {
|
|
1923
|
-
if (!oldDiffLine) {
|
|
1924
|
-
newFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldLineNumber);
|
|
1925
|
-
}
|
|
1926
|
-
oldLineNumber++;
|
|
1927
|
-
}
|
|
1928
|
-
if (!hasSymbolChanged && newDiffLine && oldDiffLine) {
|
|
1929
|
-
hasSymbolChanged = hasSymbolChanged || newDiffLine.noTrailingNewLine !== oldDiffLine.noTrailingNewLine;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
if (!hasSymbolChanged && newFileContent === this._oldFileContent)
|
|
1933
|
-
return;
|
|
1934
|
-
this._newFileContent = newFileContent;
|
|
1935
|
-
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName));
|
|
1936
|
-
this.fileLineLength = Math.max(this.fileLineLength, __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber);
|
|
1937
|
-
}
|
|
1938
|
-
else if (__classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) {
|
|
1939
|
-
let oldLineNumber = 1;
|
|
1940
|
-
let newLineNumber = 1;
|
|
1941
|
-
let oldFileContent = "";
|
|
1942
|
-
let hasSymbolChanged = false;
|
|
1943
|
-
while (newLineNumber <= __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber) {
|
|
1944
|
-
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber++);
|
|
1945
|
-
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber);
|
|
1946
|
-
if (oldDiffLine) {
|
|
1947
|
-
oldFileContent += oldDiffLine.text;
|
|
1948
|
-
newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
|
|
1949
|
-
}
|
|
1950
|
-
else {
|
|
1951
|
-
if (!newDiffLine) {
|
|
1952
|
-
oldFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newLineNumber);
|
|
1953
|
-
}
|
|
1954
|
-
newLineNumber++;
|
|
1955
|
-
}
|
|
1956
|
-
if (!hasSymbolChanged && newDiffLine && oldDiffLine) {
|
|
1957
|
-
hasSymbolChanged = hasSymbolChanged || newDiffLine.noTrailingNewLine !== oldDiffLine.noTrailingNewLine;
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
if (!hasSymbolChanged && oldFileContent === this._newFileContent)
|
|
1961
|
-
return;
|
|
1962
|
-
this._oldFileContent = oldFileContent;
|
|
1963
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName));
|
|
1964
|
-
this.fileLineLength = Math.max(this.fileLineLength, __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber);
|
|
1965
|
-
}
|
|
1966
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
|
|
1967
|
-
}, _DiffFile_composeDiff = function _DiffFile_composeDiff() {
|
|
1968
|
-
var _a;
|
|
1969
|
-
if (!((_a = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f")) === null || _a === void 0 ? void 0 : _a.length))
|
|
1970
|
-
return;
|
|
1971
|
-
__classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
|
|
1972
|
-
const hunks = item.hunks;
|
|
1973
|
-
hunks.forEach((hunk) => {
|
|
1974
|
-
let additions = [];
|
|
1975
|
-
let deletions = [];
|
|
1976
|
-
hunk.lines.forEach((line) => {
|
|
1977
|
-
if (line.type === exports.DiffLineType.Add) {
|
|
1978
|
-
additions.push(line);
|
|
1979
|
-
}
|
|
1980
|
-
else if (line.type === exports.DiffLineType.Delete) {
|
|
1981
|
-
deletions.push(line);
|
|
1982
|
-
}
|
|
1983
|
-
else {
|
|
1984
|
-
getDiffRange(additions, deletions);
|
|
1985
|
-
additions = [];
|
|
1986
|
-
deletions = [];
|
|
1987
|
-
}
|
|
1988
|
-
});
|
|
1989
|
-
getDiffRange(additions, deletions);
|
|
1990
|
-
});
|
|
1991
|
-
});
|
|
1992
|
-
__classPrivateFieldSet(this, _DiffFile_diffLines, []);
|
|
1993
|
-
const tmp = [];
|
|
1994
|
-
__classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
|
|
1995
|
-
item.hunks.forEach((_item) => {
|
|
1996
|
-
tmp.push(..._item.lines);
|
|
1997
|
-
});
|
|
1998
|
-
});
|
|
1999
|
-
__classPrivateFieldSet(this, _DiffFile_diffLines, tmp.map((i, index) => {
|
|
2000
|
-
var _a;
|
|
2001
|
-
const typedI = i;
|
|
2002
|
-
typedI.index = index;
|
|
2003
|
-
if (typedI.type === exports.DiffLineType.Hunk) {
|
|
2004
|
-
const numInfo = (_a = typedI.text.split("@@")) === null || _a === void 0 ? void 0 : _a[1].split(" ").filter(Boolean);
|
|
2005
|
-
const oldNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[0]) || "";
|
|
2006
|
-
const newNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[1]) || "";
|
|
2007
|
-
const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
2008
|
-
const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
2009
|
-
const typedTypeI = typedI;
|
|
2010
|
-
typedTypeI.hunkInfo = {
|
|
2011
|
-
oldStartIndex: -Number(oldNumStartIndex),
|
|
2012
|
-
oldLength: Number(oldNumLength),
|
|
2013
|
-
newStartIndex: +Number(newNumStartIndex),
|
|
2014
|
-
newLength: Number(newNumLength),
|
|
2015
|
-
_oldStartIndex: -Number(oldNumStartIndex),
|
|
2016
|
-
_oldLength: Number(oldNumLength),
|
|
2017
|
-
_newStartIndex: +Number(newNumStartIndex),
|
|
2018
|
-
_newLength: Number(newNumLength),
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
return typedI;
|
|
2022
|
-
}));
|
|
2023
|
-
// this.#diffLines = this.#diffListResults
|
|
2024
|
-
// .reduce<DiffLine[]>((p, c) => p.concat(...c.hunks.reduce<DiffLine[]>((_p, _c) => _p.concat(..._c.lines), [])), [])
|
|
2025
|
-
// .map<DiffLineItem>((i, index) => {
|
|
2026
|
-
// const typedI = i as DiffLineItem;
|
|
2027
|
-
// typedI.index = index;
|
|
2028
|
-
// if (typedI.type === DiffLineType.Hunk) {
|
|
2029
|
-
// const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
|
|
2030
|
-
// const oldNumInfo = numInfo?.[0] || "";
|
|
2031
|
-
// const newNumInfo = numInfo?.[1] || "";
|
|
2032
|
-
// const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
2033
|
-
// const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
2034
|
-
// const typedTypeI = typedI as DiffHunkItem;
|
|
2035
|
-
// typedTypeI.hunkInfo = {
|
|
2036
|
-
// oldStartIndex: -Number(oldNumStartIndex),
|
|
2037
|
-
// oldLength: Number(oldNumLength),
|
|
2038
|
-
// newStartIndex: +Number(newNumStartIndex),
|
|
2039
|
-
// newLength: Number(newNumLength),
|
|
2040
|
-
// };
|
|
2041
|
-
// }
|
|
2042
|
-
// return typedI;
|
|
2043
|
-
// });
|
|
2044
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, {});
|
|
2045
|
-
__classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
|
|
2046
|
-
if (item.oldLineNumber) {
|
|
2047
|
-
this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
|
|
2048
|
-
__classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")[item.oldLineNumber] = item;
|
|
2049
|
-
}
|
|
2050
|
-
});
|
|
2051
|
-
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, {});
|
|
2052
|
-
__classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
|
|
2053
|
-
if (item.newLineNumber) {
|
|
2054
|
-
this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
|
|
2055
|
-
__classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")[item.newLineNumber] = item;
|
|
2056
|
-
}
|
|
2057
|
-
});
|
|
2058
|
-
}, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({ registerHighlighter }) {
|
|
2059
|
-
var _a, _b, _c, _d;
|
|
2060
|
-
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({ registerHighlighter });
|
|
2061
|
-
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.syntaxFile);
|
|
2062
|
-
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({ registerHighlighter });
|
|
2063
|
-
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.syntaxFile);
|
|
2064
|
-
}, _DiffFile_getOldDiffLine = function _DiffFile_getOldDiffLine(lineNumber) {
|
|
2065
|
-
var _a;
|
|
2066
|
-
if (!lineNumber)
|
|
2067
|
-
return;
|
|
2068
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
2069
|
-
}, _DiffFile_getNewDiffLine = function _DiffFile_getNewDiffLine(lineNumber) {
|
|
2070
|
-
var _a;
|
|
2071
|
-
if (!lineNumber)
|
|
2072
|
-
return;
|
|
2073
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
2074
|
-
}, _DiffFile_getOldRawLine = function _DiffFile_getOldRawLine(lineNumber) {
|
|
2075
|
-
var _a;
|
|
2076
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
2077
|
-
}, _DiffFile_getNewRawLine = function _DiffFile_getNewRawLine(lineNumber) {
|
|
2078
|
-
var _a;
|
|
2079
|
-
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
exports.DiffFileLineType = void 0;
|
|
2083
|
-
(function (DiffFileLineType) {
|
|
2084
|
-
DiffFileLineType[DiffFileLineType["hunk"] = 1] = "hunk";
|
|
2085
|
-
DiffFileLineType[DiffFileLineType["content"] = 2] = "content";
|
|
2086
|
-
DiffFileLineType[DiffFileLineType["widget"] = 3] = "widget";
|
|
2087
|
-
DiffFileLineType[DiffFileLineType["extend"] = 4] = "extend";
|
|
2088
|
-
})(exports.DiffFileLineType || (exports.DiffFileLineType = {}));
|
|
2089
|
-
const getSplitLines = (diffFile, options) => {
|
|
2090
|
-
const splitLineLength = diffFile.splitLineLength;
|
|
2091
|
-
const splitLines = [];
|
|
2092
|
-
numIterator(splitLineLength, (index) => {
|
|
2093
|
-
var _a, _b;
|
|
2094
|
-
const hunkLine = diffFile.getSplitHunkLine(index);
|
|
2095
|
-
const splitLeftLine = diffFile.getSplitLeftLine(index);
|
|
2096
|
-
const splitRightLine = diffFile.getSplitRightLine(index);
|
|
2097
|
-
const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
|
|
2098
|
-
const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
|
|
2099
|
-
hunkLine &&
|
|
2100
|
-
hunkLine.splitInfo &&
|
|
2101
|
-
hunkLine.splitInfo.startHiddenIndex < hunkLine.splitInfo.endHiddenIndex &&
|
|
2102
|
-
splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2103
|
-
hunkLine &&
|
|
2104
|
-
!hunkLine.splitInfo &&
|
|
2105
|
-
!hunkLine.unifiedInfo &&
|
|
2106
|
-
hunkLine.type === exports.DiffLineType.Hunk &&
|
|
2107
|
-
splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2108
|
-
!(splitLeftLine === null || splitLeftLine === void 0 ? void 0 : splitLeftLine.isHidden) &&
|
|
2109
|
-
!(splitRightLine === null || splitRightLine === void 0 ? void 0 : splitRightLine.isHidden) &&
|
|
2110
|
-
splitLines.push({
|
|
2111
|
-
type: exports.DiffFileLineType.content,
|
|
2112
|
-
index,
|
|
2113
|
-
lineNumber: index + 1,
|
|
2114
|
-
splitLine: { left: splitLeftLine, right: splitRightLine },
|
|
2115
|
-
});
|
|
2116
|
-
widgetLine &&
|
|
2117
|
-
splitLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2118
|
-
extendLine &&
|
|
2119
|
-
splitLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2120
|
-
});
|
|
2121
|
-
return splitLines;
|
|
2122
|
-
};
|
|
2123
|
-
const getSplitContentLines = (diffFile) => {
|
|
2124
|
-
const lines = getSplitLines(diffFile, {});
|
|
2125
|
-
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
2126
|
-
};
|
|
2127
|
-
const getUnifiedLines = (diffFile, options) => {
|
|
2128
|
-
const unifiedLineLength = diffFile.unifiedLineLength;
|
|
2129
|
-
const unifiedLines = [];
|
|
2130
|
-
numIterator(unifiedLineLength, (index) => {
|
|
2131
|
-
var _a, _b;
|
|
2132
|
-
const hunkLine = diffFile.getUnifiedHunkLine(index);
|
|
2133
|
-
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
2134
|
-
const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
|
|
2135
|
-
const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
|
|
2136
|
-
hunkLine &&
|
|
2137
|
-
hunkLine.unifiedInfo &&
|
|
2138
|
-
hunkLine.unifiedInfo.startHiddenIndex < hunkLine.unifiedInfo.endHiddenIndex &&
|
|
2139
|
-
unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2140
|
-
hunkLine &&
|
|
2141
|
-
!hunkLine.splitInfo &&
|
|
2142
|
-
!hunkLine.unifiedInfo &&
|
|
2143
|
-
hunkLine.type === exports.DiffLineType.Hunk &&
|
|
2144
|
-
unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2145
|
-
!unifiedLine.isHidden &&
|
|
2146
|
-
unifiedLines.push({ type: exports.DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
|
|
2147
|
-
widgetLine &&
|
|
2148
|
-
unifiedLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2149
|
-
extendLine &&
|
|
2150
|
-
unifiedLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2151
|
-
});
|
|
2152
|
-
return unifiedLines;
|
|
2153
|
-
};
|
|
2154
|
-
const getUnifiedContentLine = (diffFile) => {
|
|
2155
|
-
const lines = getUnifiedLines(diffFile, {});
|
|
2156
|
-
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
2157
|
-
};
|
|
2158
|
-
|
|
2159
|
-
const versions = "0.0.13";
|
|
2160
|
-
|
|
2161
75
|
const useUnmount = (cb, deps) => {
|
|
2162
76
|
const ref = React.useRef(cb);
|
|
2163
77
|
ref.current = cb;
|
|
@@ -2177,14 +91,14 @@ class TextMeasure {
|
|
|
2177
91
|
}
|
|
2178
92
|
measure(text, font) {
|
|
2179
93
|
const currentKey = `${font === null || font === void 0 ? void 0 : font.fontFamily}-${font === null || font === void 0 ? void 0 : font.fontStyle}-${font === null || font === void 0 ? void 0 : font.fontSize}-${text}`;
|
|
2180
|
-
if (__classPrivateFieldGet
|
|
2181
|
-
return __classPrivateFieldGet
|
|
94
|
+
if (__classPrivateFieldGet(this, _TextMeasure_map, "f")[currentKey]) {
|
|
95
|
+
return __classPrivateFieldGet(this, _TextMeasure_map, "f")[currentKey];
|
|
2182
96
|
}
|
|
2183
|
-
const instance = __classPrivateFieldGet
|
|
97
|
+
const instance = __classPrivateFieldGet(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
|
|
2184
98
|
if (font) {
|
|
2185
99
|
const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
|
|
2186
|
-
if (__classPrivateFieldGet
|
|
2187
|
-
__classPrivateFieldSet
|
|
100
|
+
if (__classPrivateFieldGet(this, _TextMeasure_key, "f") !== currentFontKey) {
|
|
101
|
+
__classPrivateFieldSet(this, _TextMeasure_key, currentFontKey, "f");
|
|
2188
102
|
instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
|
|
2189
103
|
}
|
|
2190
104
|
}
|
|
@@ -2463,8 +377,8 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2463
377
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
2464
378
|
const isExpandAll = currentHunk &&
|
|
2465
379
|
currentHunk.splitInfo &&
|
|
2466
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
2467
|
-
const isFirstLine = currentHunk && currentHunk.
|
|
380
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
381
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
2468
382
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
2469
383
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2470
384
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
@@ -2501,8 +415,8 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2501
415
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
2502
416
|
const isExpandAll = currentHunk &&
|
|
2503
417
|
currentHunk.splitInfo &&
|
|
2504
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
2505
|
-
const isFirstLine = currentHunk && currentHunk.
|
|
418
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
419
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
2506
420
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
2507
421
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
2508
422
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
@@ -2625,16 +539,16 @@ const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
|
2625
539
|
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
2626
540
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
2627
541
|
} }, isLast
|
|
2628
|
-
? `${_str2}${isNewLineSymbolChanged ===
|
|
542
|
+
? `${_str2}${isNewLineSymbolChanged === core.NewLineSymbol.LF
|
|
2629
543
|
? "␊"
|
|
2630
|
-
: isNewLineSymbolChanged ===
|
|
544
|
+
: isNewLineSymbolChanged === core.NewLineSymbol.CR
|
|
2631
545
|
? "␍"
|
|
2632
|
-
: isNewLineSymbolChanged ===
|
|
546
|
+
: isNewLineSymbolChanged === core.NewLineSymbol.CRLF
|
|
2633
547
|
? "␍␊"
|
|
2634
548
|
: ""}`
|
|
2635
549
|
: str2),
|
|
2636
550
|
str3),
|
|
2637
|
-
isNewLineSymbolChanged ===
|
|
551
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
|
|
2638
552
|
width: `var(${diffFontSizeName})`,
|
|
2639
553
|
height: `var(${diffFontSizeName})`,
|
|
2640
554
|
} },
|
|
@@ -2675,18 +589,18 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
2675
589
|
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
2676
590
|
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
2677
591
|
} }, isLast
|
|
2678
|
-
? `${_str2}${isNewLineSymbolChanged ===
|
|
592
|
+
? `${_str2}${isNewLineSymbolChanged === core.NewLineSymbol.LF
|
|
2679
593
|
? "␊"
|
|
2680
|
-
: isNewLineSymbolChanged ===
|
|
594
|
+
: isNewLineSymbolChanged === core.NewLineSymbol.CR
|
|
2681
595
|
? "␍"
|
|
2682
|
-
: isNewLineSymbolChanged ===
|
|
596
|
+
: isNewLineSymbolChanged === core.NewLineSymbol.CRLF
|
|
2683
597
|
? "␍␊"
|
|
2684
598
|
: ""}`
|
|
2685
599
|
: str2),
|
|
2686
600
|
str3));
|
|
2687
601
|
}
|
|
2688
602
|
})),
|
|
2689
|
-
isNewLineSymbolChanged ===
|
|
603
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
|
|
2690
604
|
width: `var(${diffFontSizeName})`,
|
|
2691
605
|
height: `var(${diffFontSizeName})`,
|
|
2692
606
|
} },
|
|
@@ -2699,8 +613,8 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
2699
613
|
};
|
|
2700
614
|
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
2701
615
|
var _a;
|
|
2702
|
-
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) ===
|
|
2703
|
-
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) ===
|
|
616
|
+
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
|
|
617
|
+
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
|
|
2704
618
|
const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
|
|
2705
619
|
return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
|
|
2706
620
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
@@ -2722,9 +636,9 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
2722
636
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
2723
637
|
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
2724
638
|
const hasContent = !!currentLine.lineNumber;
|
|
2725
|
-
const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
2726
|
-
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
2727
|
-
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) ===
|
|
639
|
+
const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
640
|
+
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
|
|
641
|
+
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
|
|
2728
642
|
const { useDiffContext } = useDiffViewContext();
|
|
2729
643
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
2730
644
|
enableHighlight: s.enableHighlight,
|
|
@@ -2809,7 +723,7 @@ const onMouseDown$1 = (e) => {
|
|
|
2809
723
|
};
|
|
2810
724
|
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
2811
725
|
const className = side === exports.SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
2812
|
-
const lines = getSplitContentLines(diffFile);
|
|
726
|
+
const lines = core.getSplitContentLines(diffFile);
|
|
2813
727
|
return (React__namespace.createElement("table", { className: className + " border-collapse w-full", "data-mode": exports.SplitSide[side] },
|
|
2814
728
|
React__namespace.createElement("colgroup", null,
|
|
2815
729
|
React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col` }),
|
|
@@ -2836,7 +750,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
2836
750
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
2837
751
|
const { useDiffContext } = useDiffViewContext();
|
|
2838
752
|
const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
|
|
2839
|
-
|
|
753
|
+
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
2840
754
|
React.useEffect(() => {
|
|
2841
755
|
const left = ref1.current;
|
|
2842
756
|
const right = ref2.current;
|
|
@@ -2928,12 +842,12 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
|
2928
842
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
2929
843
|
const isExpandAll = currentHunk &&
|
|
2930
844
|
currentHunk.splitInfo &&
|
|
2931
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
845
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
2932
846
|
const currentIsShow = currentHunk &&
|
|
2933
847
|
currentHunk.splitInfo &&
|
|
2934
848
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
2935
849
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
2936
|
-
const isFirstLine = currentHunk && currentHunk.
|
|
850
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
2937
851
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
2938
852
|
if (!currentIsShow && !currentIsPureHunk)
|
|
2939
853
|
return null;
|
|
@@ -2961,12 +875,12 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
2961
875
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
2962
876
|
const isExpandAll = currentHunk &&
|
|
2963
877
|
currentHunk.splitInfo &&
|
|
2964
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
878
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
2965
879
|
const currentIsShow = currentHunk &&
|
|
2966
880
|
currentHunk.splitInfo &&
|
|
2967
881
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
2968
882
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
2969
|
-
const isFirstLine = currentHunk && currentHunk.
|
|
883
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
2970
884
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
2971
885
|
if (!currentIsShow && !currentIsPureHunk)
|
|
2972
886
|
return null;
|
|
@@ -3022,9 +936,9 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
3022
936
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
3023
937
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
3024
938
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
3025
|
-
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
3026
|
-
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
3027
|
-
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) ===
|
|
939
|
+
const hasChange = core.checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || core.checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
940
|
+
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Delete;
|
|
941
|
+
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Add;
|
|
3028
942
|
const { useDiffContext } = useDiffViewContext();
|
|
3029
943
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
3030
944
|
enableHighlight: s.enableHighlight,
|
|
@@ -3127,7 +1041,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
3127
1041
|
}), []);
|
|
3128
1042
|
const setSelectSide = splitSideInfo.getReadonlyState().setSplit;
|
|
3129
1043
|
const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
|
|
3130
|
-
|
|
1044
|
+
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
3131
1045
|
const onMouseDown = React.useCallback((e) => {
|
|
3132
1046
|
let ele = e.target;
|
|
3133
1047
|
// need remove all the selection
|
|
@@ -3152,7 +1066,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
3152
1066
|
font,
|
|
3153
1067
|
});
|
|
3154
1068
|
const width = Math.max(40, _width + 25);
|
|
3155
|
-
const lines = getSplitContentLines(diffFile);
|
|
1069
|
+
const lines = core.getSplitContentLines(diffFile);
|
|
3156
1070
|
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
|
|
3157
1071
|
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
3158
1072
|
fontFamily: "Menlo, Consolas, monospace",
|
|
@@ -3263,8 +1177,8 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3263
1177
|
const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
|
|
3264
1178
|
const isExpandAll = currentHunk &&
|
|
3265
1179
|
currentHunk.unifiedInfo &&
|
|
3266
|
-
currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen;
|
|
3267
|
-
const isFirstLine = currentHunk && currentHunk.
|
|
1180
|
+
currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < core.composeLen;
|
|
1181
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
3268
1182
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
3269
1183
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
3270
1184
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
|
|
@@ -3345,7 +1259,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
3345
1259
|
const { useWidget } = useDiffWidgetContext();
|
|
3346
1260
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
3347
1261
|
const hasDiff = unifiedLine.diff;
|
|
3348
|
-
const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
|
|
1262
|
+
const hasChange = core.checkDiffLineIncludeChange(unifiedLine.diff);
|
|
3349
1263
|
const rawLine = unifiedLine.value || "";
|
|
3350
1264
|
const diffLine = unifiedLine.diff;
|
|
3351
1265
|
const newLineNumber = unifiedLine.newLineNumber;
|
|
@@ -3451,7 +1365,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
3451
1365
|
}), [useDiffContext]);
|
|
3452
1366
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
3453
1367
|
const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
|
|
3454
|
-
|
|
1368
|
+
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
3455
1369
|
React.useEffect(() => {
|
|
3456
1370
|
const { setWidget } = useWidget.getReadonlyState();
|
|
3457
1371
|
setWidget({});
|
|
@@ -3462,7 +1376,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
3462
1376
|
font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
|
|
3463
1377
|
});
|
|
3464
1378
|
const width = Math.max(40, _width + 25);
|
|
3465
|
-
const lines = getUnifiedContentLine(diffFile);
|
|
1379
|
+
const lines = core.getUnifiedContentLine(diffFile);
|
|
3466
1380
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
3467
1381
|
React__namespace.createElement("div", { className: "unified-diff-view w-full" },
|
|
3468
1382
|
React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-x-auto overflow-y-hidden w-full scrollbar-hide scrollbar-disable", style: {
|
|
@@ -3490,7 +1404,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
3490
1404
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
3491
1405
|
|
|
3492
1406
|
const diffFontSizeName = "--diff-font-size--";
|
|
3493
|
-
_cacheMap.name = "@git-diff-view/react";
|
|
1407
|
+
core._cacheMap.name = "@git-diff-view/react";
|
|
3494
1408
|
exports.SplitSide = void 0;
|
|
3495
1409
|
(function (SplitSide) {
|
|
3496
1410
|
SplitSide[SplitSide["old"] = 1] = "old";
|
|
@@ -3545,8 +1459,8 @@ const _InternalDiffView = (props) => {
|
|
|
3545
1459
|
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
3546
1460
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
3547
1461
|
// 避免无意义的订阅
|
|
3548
|
-
const onAddWidgetClick =
|
|
3549
|
-
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.
|
|
1462
|
+
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1463
|
+
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
3550
1464
|
return {
|
|
3551
1465
|
id,
|
|
3552
1466
|
setId,
|
|
@@ -3599,7 +1513,7 @@ const _InternalDiffView = (props) => {
|
|
|
3599
1513
|
]);
|
|
3600
1514
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
3601
1515
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
3602
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.
|
|
1516
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.14"}`, "data-highlighter": diffFile._getHighlighterName() },
|
|
3603
1517
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
3604
1518
|
// @ts-ignore
|
|
3605
1519
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -3612,12 +1526,12 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
3612
1526
|
const diffFile = React.useMemo(() => {
|
|
3613
1527
|
var _a, _b, _c, _d, _e, _f;
|
|
3614
1528
|
if (_diffFile) {
|
|
3615
|
-
const diffFile = DiffFile.createInstance({});
|
|
1529
|
+
const diffFile = core.DiffFile.createInstance({});
|
|
3616
1530
|
diffFile._mergeFullBundle(_diffFile._getFullBundle());
|
|
3617
1531
|
return diffFile;
|
|
3618
1532
|
}
|
|
3619
1533
|
else if (data) {
|
|
3620
|
-
return new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
|
|
1534
|
+
return new core.DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
|
|
3621
1535
|
}
|
|
3622
1536
|
return null;
|
|
3623
1537
|
}, [data, _diffFile]);
|
|
@@ -3644,7 +1558,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
3644
1558
|
};
|
|
3645
1559
|
}
|
|
3646
1560
|
}, [diffFile, _diffFile]);
|
|
3647
|
-
useUnmount(() => diffFile._destroy(), [diffFile]);
|
|
1561
|
+
useUnmount(() => { var _a; return (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile._destroy) === null || _a === void 0 ? void 0 : _a.call(diffFile); }, [diffFile]);
|
|
3648
1562
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
3649
1563
|
if (!diffFile)
|
|
3650
1564
|
return null;
|
|
@@ -3652,39 +1566,17 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
3652
1566
|
};
|
|
3653
1567
|
const DiffView = React.forwardRef(DiffViewWithRef);
|
|
3654
1568
|
DiffView.displayName = "DiffView";
|
|
3655
|
-
const version = "0.0.
|
|
1569
|
+
const version = "0.0.14";
|
|
3656
1570
|
|
|
3657
|
-
exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
|
|
3658
|
-
exports.DiffFile = DiffFile;
|
|
3659
|
-
exports.DiffHunk = DiffHunk;
|
|
3660
|
-
exports.DiffHunkHeader = DiffHunkHeader;
|
|
3661
|
-
exports.DiffLine = DiffLine;
|
|
3662
|
-
exports.DiffParser = DiffParser;
|
|
3663
1571
|
exports.DiffView = DiffView;
|
|
3664
1572
|
exports.DiffViewContext = DiffViewContext;
|
|
3665
|
-
exports.File = File;
|
|
3666
|
-
exports.HiddenBidiCharsRegex = HiddenBidiCharsRegex;
|
|
3667
|
-
exports._cacheMap = _cacheMap;
|
|
3668
|
-
exports.assertNever = assertNever;
|
|
3669
|
-
exports.checkDiffLineIncludeChange = checkDiffLineIncludeChange;
|
|
3670
|
-
exports.composeLen = composeLen;
|
|
3671
1573
|
exports.diffFontSizeName = diffFontSizeName;
|
|
3672
|
-
exports.getDiffRange = getDiffRange;
|
|
3673
|
-
exports.getFile = getFile;
|
|
3674
|
-
exports.getHunkHeaderExpansionType = getHunkHeaderExpansionType;
|
|
3675
|
-
exports.getLang = getLang;
|
|
3676
|
-
exports.getLargestLineNumber = getLargestLineNumber;
|
|
3677
|
-
exports.getSplitContentLines = getSplitContentLines;
|
|
3678
|
-
exports.getSplitLines = getSplitLines;
|
|
3679
|
-
exports.getUnifiedContentLine = getUnifiedContentLine;
|
|
3680
|
-
exports.getUnifiedLines = getUnifiedLines;
|
|
3681
|
-
exports.hasRelativeChange = hasRelativeChange;
|
|
3682
|
-
exports.highlighter = highlighter;
|
|
3683
|
-
exports.numIterator = numIterator;
|
|
3684
|
-
exports.parseInstance = parseInstance;
|
|
3685
|
-
exports.processAST = processAST;
|
|
3686
|
-
exports.relativeChanges = relativeChanges;
|
|
3687
1574
|
exports.useDiffViewContext = useDiffViewContext;
|
|
3688
1575
|
exports.version = version;
|
|
3689
|
-
|
|
1576
|
+
Object.keys(core).forEach(function (k) {
|
|
1577
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1578
|
+
enumerable: true,
|
|
1579
|
+
get: function () { return core[k]; }
|
|
1580
|
+
});
|
|
1581
|
+
});
|
|
3690
1582
|
//# sourceMappingURL=index.development.js.map
|