@git-diff-view/react 0.0.7 → 0.0.9
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 +394 -266
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +386 -259
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +1 -1
- package/dist/esm/index.mjs +396 -269
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/components/DiffContent.d.ts.map +1 -1
- package/dist/types/components/DiffSplitExtendLineNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitExtendLineWrap.d.ts.map +1 -1
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitLineNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitView.d.ts.map +1 -1
- package/dist/types/components/DiffSplitViewNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitViewWrap.d.ts.map +1 -1
- package/dist/types/components/DiffSplitWidgetLineWrap.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedExtendLine.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedHunkLine.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedLine.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedView.d.ts.map +1 -1
- package/dist/types/components/DiffView.d.ts +0 -1
- package/dist/types/components/DiffView.d.ts.map +1 -1
- package/dist/types/components/DiffViewContext.d.ts +6 -2
- package/dist/types/components/DiffViewContext.d.ts.map +1 -1
- package/dist/types/components/tools.d.ts +2 -0
- package/dist/types/components/tools.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -107,34 +107,83 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
107
107
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
110
|
+
const processAST = (ast) => {
|
|
111
|
+
let lineNumber = 1;
|
|
112
|
+
const syntaxObj = {};
|
|
113
|
+
const loopAST = (nodes, wrapper) => {
|
|
114
|
+
nodes.forEach((node) => {
|
|
115
|
+
if (node.type === "text") {
|
|
116
|
+
if (node.value.indexOf("\n") === -1) {
|
|
117
|
+
const valueLength = node.value.length;
|
|
118
|
+
if (!syntaxObj[lineNumber]) {
|
|
119
|
+
node.startIndex = 0;
|
|
120
|
+
node.endIndex = valueLength - 1;
|
|
121
|
+
const item = {
|
|
122
|
+
value: node.value,
|
|
123
|
+
lineNumber,
|
|
124
|
+
valueLength,
|
|
125
|
+
nodeList: [{ node, wrapper }],
|
|
126
|
+
};
|
|
127
|
+
syntaxObj[lineNumber] = item;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
131
|
+
node.endIndex = node.startIndex + valueLength - 1;
|
|
132
|
+
syntaxObj[lineNumber].value += node.value;
|
|
133
|
+
syntaxObj[lineNumber].valueLength += valueLength;
|
|
134
|
+
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
135
|
+
}
|
|
136
|
+
node.lineNumber = lineNumber;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const lines = node.value.split("\n");
|
|
140
|
+
node.children = node.children || [];
|
|
141
|
+
for (let i = 0; i < lines.length; i++) {
|
|
142
|
+
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
143
|
+
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
144
|
+
const _valueLength = _value.length;
|
|
145
|
+
const _node = {
|
|
146
|
+
type: "text",
|
|
147
|
+
value: _value,
|
|
148
|
+
startIndex: Infinity,
|
|
149
|
+
endIndex: Infinity,
|
|
150
|
+
lineNumber: _lineNumber,
|
|
151
|
+
};
|
|
152
|
+
if (!syntaxObj[_lineNumber]) {
|
|
153
|
+
_node.startIndex = 0;
|
|
154
|
+
_node.endIndex = _valueLength - 1;
|
|
155
|
+
const item = {
|
|
156
|
+
value: _value,
|
|
157
|
+
lineNumber: _lineNumber,
|
|
158
|
+
valueLength: _valueLength,
|
|
159
|
+
nodeList: [{ node: _node, wrapper }],
|
|
160
|
+
};
|
|
161
|
+
syntaxObj[_lineNumber] = item;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
165
|
+
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
166
|
+
syntaxObj[_lineNumber].value += _value;
|
|
167
|
+
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
168
|
+
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
169
|
+
}
|
|
170
|
+
node.children.push(_node);
|
|
171
|
+
}
|
|
172
|
+
node.lineNumber = lineNumber;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (node.children) {
|
|
176
|
+
loopAST(node.children, node);
|
|
177
|
+
node.lineNumber = lineNumber;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
loopAST(ast.children);
|
|
182
|
+
return { syntaxFileObject: syntaxObj, syntaxFileLineNumber: lineNumber };
|
|
183
|
+
};
|
|
136
184
|
|
|
137
185
|
const lowlight = lowlight$1.createLowlight(lowlight$1.all);
|
|
186
|
+
// !SEE https://github.com/highlightjs/highlightjs-vue
|
|
138
187
|
lowlight.register("vue", function hljsDefineVue(hljs) {
|
|
139
188
|
return {
|
|
140
189
|
subLanguage: "xml",
|
|
@@ -180,50 +229,95 @@ lowlight.register("vue", function hljsDefineVue(hljs) {
|
|
|
180
229
|
],
|
|
181
230
|
};
|
|
182
231
|
});
|
|
183
|
-
const
|
|
184
|
-
let _autoDetectLang = true;
|
|
232
|
+
const instance = { name: "lowlight" };
|
|
185
233
|
let _maxLineToIgnoreSyntax = 2000;
|
|
186
234
|
const _ignoreSyntaxHighlightList = [];
|
|
187
|
-
Object.defineProperty(
|
|
235
|
+
Object.defineProperty(instance, "maxLineToIgnoreSyntax", {
|
|
188
236
|
get: () => _maxLineToIgnoreSyntax,
|
|
189
237
|
});
|
|
190
|
-
Object.defineProperty(
|
|
238
|
+
Object.defineProperty(instance, "setMaxLineToIgnoreSyntax", {
|
|
191
239
|
value: (v) => {
|
|
192
240
|
_maxLineToIgnoreSyntax = v;
|
|
193
241
|
},
|
|
194
242
|
});
|
|
195
|
-
Object.defineProperty(
|
|
196
|
-
get: () => _autoDetectLang,
|
|
197
|
-
});
|
|
198
|
-
Object.defineProperty(highlighter, "setAutoDetectLang", {
|
|
199
|
-
value: (v) => {
|
|
200
|
-
_autoDetectLang = v;
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
Object.defineProperty(highlighter, "ignoreSyntaxHighlightList", {
|
|
243
|
+
Object.defineProperty(instance, "ignoreSyntaxHighlightList", {
|
|
204
244
|
get: () => _ignoreSyntaxHighlightList,
|
|
205
245
|
});
|
|
206
|
-
Object.defineProperty(
|
|
246
|
+
Object.defineProperty(instance, "setIgnoreSyntaxHighlightList", {
|
|
207
247
|
value: (v) => {
|
|
208
248
|
_ignoreSyntaxHighlightList.length = 0;
|
|
209
249
|
_ignoreSyntaxHighlightList.push(...v);
|
|
210
250
|
},
|
|
211
251
|
});
|
|
252
|
+
Object.defineProperty(instance, "getAST", {
|
|
253
|
+
value: (raw, fileName, lang) => {
|
|
254
|
+
let hasRegisteredLang = true;
|
|
255
|
+
if (!lowlight.registered(lang)) {
|
|
256
|
+
console.warn(`not support current lang: ${lang} yet`);
|
|
257
|
+
hasRegisteredLang = false;
|
|
258
|
+
}
|
|
259
|
+
if (fileName &&
|
|
260
|
+
highlighter.ignoreSyntaxHighlightList.some((item) => item instanceof RegExp ? item.test(fileName) : fileName === item)) {
|
|
261
|
+
console.warn(`ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}`);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (hasRegisteredLang) {
|
|
265
|
+
return lowlight.highlight(lang, raw);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
return lowlight.highlightAuto(raw);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
Object.defineProperty(instance, "processAST", {
|
|
273
|
+
value: (ast) => {
|
|
274
|
+
return processAST(ast);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
const highlighter = instance;
|
|
212
278
|
|
|
213
|
-
var
|
|
279
|
+
var _Cache_keyArray, _Cache_maxLength;
|
|
280
|
+
class Cache extends Map {
|
|
281
|
+
constructor() {
|
|
282
|
+
super(...arguments);
|
|
283
|
+
_Cache_keyArray.set(this, []);
|
|
284
|
+
_Cache_maxLength.set(this, 30);
|
|
285
|
+
}
|
|
286
|
+
setMaxLength(length) {
|
|
287
|
+
__classPrivateFieldSet(this, _Cache_maxLength, length, "f");
|
|
288
|
+
this._checkLength();
|
|
289
|
+
}
|
|
290
|
+
set(key, value) {
|
|
291
|
+
if (this.has(key))
|
|
292
|
+
return this;
|
|
293
|
+
__classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
|
|
294
|
+
this._checkLength();
|
|
295
|
+
return super.set(key, value);
|
|
296
|
+
}
|
|
297
|
+
_checkLength() {
|
|
298
|
+
while (__classPrivateFieldGet(this, _Cache_keyArray, "f").length > __classPrivateFieldGet(this, _Cache_maxLength, "f")) {
|
|
299
|
+
const key = __classPrivateFieldGet(this, _Cache_keyArray, "f").shift();
|
|
300
|
+
this.delete(key);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
_Cache_keyArray = new WeakMap(), _Cache_maxLength = new WeakMap();
|
|
305
|
+
|
|
306
|
+
var _File_instances, _File_doCheck;
|
|
214
307
|
const map = new Cache();
|
|
308
|
+
const devKey = "@git-diff-cache";
|
|
215
309
|
map.setMaxLength(50);
|
|
216
310
|
map.name = "@git-diff-view/core";
|
|
217
311
|
if (typeof globalThis !== "undefined") {
|
|
218
|
-
if (Array.isArray(globalThis
|
|
219
|
-
globalThis
|
|
220
|
-
if (globalThis.
|
|
312
|
+
if (Array.isArray(globalThis[devKey])) {
|
|
313
|
+
globalThis[devKey] = globalThis[devKey].filter((i) => i !== map);
|
|
314
|
+
if (globalThis[devKey].length > 0) {
|
|
221
315
|
console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
|
|
222
316
|
}
|
|
223
|
-
globalThis.
|
|
317
|
+
globalThis[devKey].push(map);
|
|
224
318
|
}
|
|
225
319
|
else {
|
|
226
|
-
globalThis
|
|
320
|
+
globalThis[devKey] = [map];
|
|
227
321
|
}
|
|
228
322
|
}
|
|
229
323
|
class File {
|
|
@@ -239,38 +333,25 @@ class File {
|
|
|
239
333
|
this.maxLineNumber = 0;
|
|
240
334
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
241
335
|
}
|
|
242
|
-
doSyntax({
|
|
336
|
+
doSyntax({ registerHighlighter }) {
|
|
243
337
|
if (!this.raw || this.hasDoSyntax)
|
|
244
338
|
return;
|
|
245
|
-
let hasRegisteredLang = true;
|
|
246
339
|
const _highlighter = registerHighlighter || highlighter;
|
|
247
340
|
if (this.syntaxLength) {
|
|
248
341
|
console.error("current file already doSyntax before!");
|
|
249
342
|
return;
|
|
250
343
|
}
|
|
251
|
-
if (!_highlighter.registered(this.lang)) {
|
|
252
|
-
hasRegisteredLang = false;
|
|
253
|
-
if (!autoDetectLang) {
|
|
254
|
-
console.warn(`not support current lang: ${this.lang} yet`);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
344
|
if (this.rawLength > _highlighter.maxLineToIgnoreSyntax) {
|
|
259
345
|
console.warn(`ignore syntax for current file, because the rawLength is too long: ${this.rawLength}`);
|
|
260
346
|
return;
|
|
261
347
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
console.warn(`ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${this.fileName}`);
|
|
348
|
+
this.ast = _highlighter.getAST(this.raw, this.fileName, this.lang);
|
|
349
|
+
if (!this.ast)
|
|
265
350
|
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
else {
|
|
271
|
-
this.ast = _highlighter.highlightAuto(this.raw);
|
|
272
|
-
}
|
|
273
|
-
__classPrivateFieldGet(this, _File_instances, "m", _File_doAST).call(this);
|
|
351
|
+
const { syntaxFileObject, syntaxFileLineNumber } = _highlighter.processAST(this.ast);
|
|
352
|
+
this.syntaxFile = syntaxFileObject;
|
|
353
|
+
this.syntaxLength = syntaxFileLineNumber;
|
|
354
|
+
this.highlighterName = _highlighter.name;
|
|
274
355
|
{
|
|
275
356
|
__classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
|
|
276
357
|
}
|
|
@@ -298,81 +379,7 @@ class File {
|
|
|
298
379
|
this.hasDoRaw = true;
|
|
299
380
|
}
|
|
300
381
|
}
|
|
301
|
-
_File_instances = new WeakSet(),
|
|
302
|
-
const ast = this.ast;
|
|
303
|
-
let lineNumber = 1;
|
|
304
|
-
const syntaxObj = this.syntaxFile;
|
|
305
|
-
const loopAST = (nodes, wrapper) => {
|
|
306
|
-
nodes.forEach((node) => {
|
|
307
|
-
if (node.type === "text") {
|
|
308
|
-
if (node.value.indexOf("\n") === -1) {
|
|
309
|
-
const valueLength = node.value.length;
|
|
310
|
-
if (!syntaxObj[lineNumber]) {
|
|
311
|
-
node.startIndex = 0;
|
|
312
|
-
node.endIndex = valueLength - 1;
|
|
313
|
-
const item = {
|
|
314
|
-
value: node.value,
|
|
315
|
-
lineNumber,
|
|
316
|
-
valueLength,
|
|
317
|
-
nodeList: [{ node, wrapper }],
|
|
318
|
-
};
|
|
319
|
-
syntaxObj[lineNumber] = item;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
323
|
-
node.endIndex = node.startIndex + valueLength - 1;
|
|
324
|
-
syntaxObj[lineNumber].value += node.value;
|
|
325
|
-
syntaxObj[lineNumber].valueLength += valueLength;
|
|
326
|
-
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
327
|
-
}
|
|
328
|
-
node.lineNumber = lineNumber;
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const lines = node.value.split("\n");
|
|
332
|
-
node.children = node.children || [];
|
|
333
|
-
for (let i = 0; i < lines.length; i++) {
|
|
334
|
-
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
335
|
-
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
336
|
-
const _valueLength = _value.length;
|
|
337
|
-
const _node = {
|
|
338
|
-
type: "text",
|
|
339
|
-
value: _value,
|
|
340
|
-
startIndex: Infinity,
|
|
341
|
-
endIndex: Infinity,
|
|
342
|
-
lineNumber: _lineNumber,
|
|
343
|
-
};
|
|
344
|
-
if (!syntaxObj[_lineNumber]) {
|
|
345
|
-
_node.startIndex = 0;
|
|
346
|
-
_node.endIndex = _valueLength - 1;
|
|
347
|
-
const item = {
|
|
348
|
-
value: _value,
|
|
349
|
-
lineNumber: _lineNumber,
|
|
350
|
-
valueLength: _valueLength,
|
|
351
|
-
nodeList: [{ node: _node, wrapper }],
|
|
352
|
-
};
|
|
353
|
-
syntaxObj[_lineNumber] = item;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
357
|
-
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
358
|
-
syntaxObj[_lineNumber].value += _value;
|
|
359
|
-
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
360
|
-
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
361
|
-
}
|
|
362
|
-
node.children.push(_node);
|
|
363
|
-
}
|
|
364
|
-
node.lineNumber = lineNumber;
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
if (node.children) {
|
|
368
|
-
loopAST(node.children, node);
|
|
369
|
-
node.lineNumber = lineNumber;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
loopAST(ast.children);
|
|
374
|
-
this.syntaxLength = lineNumber;
|
|
375
|
-
}, _File_doCheck = function _File_doCheck() {
|
|
382
|
+
_File_instances = new WeakSet(), _File_doCheck = function _File_doCheck() {
|
|
376
383
|
if (this.rawLength && this.syntaxLength) {
|
|
377
384
|
if (this.rawLength !== this.syntaxLength) {
|
|
378
385
|
console.warn("the rawLength not match for the syntaxLength");
|
|
@@ -385,7 +392,7 @@ _File_instances = new WeakSet(), _File_doAST = function _File_doAST() {
|
|
|
385
392
|
}
|
|
386
393
|
};
|
|
387
394
|
const getFile = (raw, lang, fileName) => {
|
|
388
|
-
const key = raw + "--" + "0.0.
|
|
395
|
+
const key = raw + "--" + "0.0.9" + "--" + lang;
|
|
389
396
|
if (map.has(key))
|
|
390
397
|
return map.get(key);
|
|
391
398
|
const file = new File(raw, lang, fileName);
|
|
@@ -683,7 +690,7 @@ const getDiffRange = (additions, deletions) => {
|
|
|
683
690
|
};
|
|
684
691
|
|
|
685
692
|
/* eslint-disable max-lines */
|
|
686
|
-
//
|
|
693
|
+
// !NOTE: ALL of the diff parse logic copy from desktop, SEE https://github.com/desktop/desktop
|
|
687
694
|
// https://en.wikipedia.org/wiki/Diff_utility
|
|
688
695
|
//
|
|
689
696
|
// @@ -l,s +l,s @@ optional section heading
|
|
@@ -1013,7 +1020,9 @@ class DiffParser {
|
|
|
1013
1020
|
}
|
|
1014
1021
|
const parseInstance = new DiffParser();
|
|
1015
1022
|
|
|
1016
|
-
|
|
1023
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1024
|
+
/* eslint-disable max-lines */
|
|
1025
|
+
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_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;
|
|
1017
1026
|
const composeLen = 40;
|
|
1018
1027
|
const idSet = new Set();
|
|
1019
1028
|
class DiffFile {
|
|
@@ -1054,7 +1063,8 @@ class DiffFile {
|
|
|
1054
1063
|
_DiffFile_hasBuildUnified.set(this, false);
|
|
1055
1064
|
_DiffFile_updateCount.set(this, 0);
|
|
1056
1065
|
_DiffFile_composeByDiff.set(this, false);
|
|
1057
|
-
this
|
|
1066
|
+
_DiffFile_highlighterName.set(this, void 0);
|
|
1067
|
+
this._version_ = "0.0.9";
|
|
1058
1068
|
this._oldFileContent = "";
|
|
1059
1069
|
this._oldFileLang = "";
|
|
1060
1070
|
this._newFileContent = "";
|
|
@@ -1062,6 +1072,9 @@ class DiffFile {
|
|
|
1062
1072
|
this.diffLineLength = 0;
|
|
1063
1073
|
this.splitLineLength = 0;
|
|
1064
1074
|
this.unifiedLineLength = 0;
|
|
1075
|
+
this.expandSplitAll = false;
|
|
1076
|
+
this.expandUnifiedAll = false;
|
|
1077
|
+
this.hasCollapsed = false;
|
|
1065
1078
|
_DiffFile_id.set(this, "");
|
|
1066
1079
|
_DiffFile_clonedInstance.set(this, new Map());
|
|
1067
1080
|
this.getSplitLeftLine = (index) => {
|
|
@@ -1200,11 +1213,13 @@ class DiffFile {
|
|
|
1200
1213
|
Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
|
|
1201
1214
|
this.onSplitHunkExpand("all", +key, false);
|
|
1202
1215
|
});
|
|
1216
|
+
this.expandSplitAll = true;
|
|
1203
1217
|
}
|
|
1204
1218
|
else {
|
|
1205
1219
|
Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
|
|
1206
1220
|
this.onUnifiedHunkExpand("all", +key, false);
|
|
1207
1221
|
});
|
|
1222
|
+
this.expandUnifiedAll = true;
|
|
1208
1223
|
}
|
|
1209
1224
|
this.notifyAll();
|
|
1210
1225
|
};
|
|
@@ -1236,6 +1251,7 @@ class DiffFile {
|
|
|
1236
1251
|
__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[item.splitInfo.endHiddenIndex] = item;
|
|
1237
1252
|
}
|
|
1238
1253
|
});
|
|
1254
|
+
this.expandSplitAll = false;
|
|
1239
1255
|
}
|
|
1240
1256
|
else {
|
|
1241
1257
|
Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f") || {}).forEach((item) => {
|
|
@@ -1257,6 +1273,7 @@ class DiffFile {
|
|
|
1257
1273
|
__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[item.unifiedInfo.endHiddenIndex] = item;
|
|
1258
1274
|
}
|
|
1259
1275
|
});
|
|
1276
|
+
this.expandUnifiedAll = false;
|
|
1260
1277
|
}
|
|
1261
1278
|
this.notifyAll();
|
|
1262
1279
|
};
|
|
@@ -1283,6 +1300,10 @@ class DiffFile {
|
|
|
1283
1300
|
}
|
|
1284
1301
|
f();
|
|
1285
1302
|
});
|
|
1303
|
+
// support update from outside instance
|
|
1304
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, instance) => {
|
|
1305
|
+
instance.notifyAll(true);
|
|
1306
|
+
});
|
|
1286
1307
|
};
|
|
1287
1308
|
this.getUpdateCount = () => __classPrivateFieldGet(this, _DiffFile_updateCount, "f");
|
|
1288
1309
|
this.getExpandEnabled = () => !__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
@@ -1303,6 +1324,8 @@ class DiffFile {
|
|
|
1303
1324
|
const splitLineLength = this.splitLineLength;
|
|
1304
1325
|
const unifiedLineLength = this.unifiedLineLength;
|
|
1305
1326
|
const composeByDiff = __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1327
|
+
const highlighterName = __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
|
|
1328
|
+
const hasCollapsed = this.hasCollapsed;
|
|
1306
1329
|
// split
|
|
1307
1330
|
const splitLeftLines = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f");
|
|
1308
1331
|
const splitRightLines = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f");
|
|
@@ -1331,7 +1354,9 @@ class DiffFile {
|
|
|
1331
1354
|
splitHunkLines,
|
|
1332
1355
|
unifiedLines,
|
|
1333
1356
|
unifiedHunkLines,
|
|
1357
|
+
highlighterName,
|
|
1334
1358
|
composeByDiff,
|
|
1359
|
+
hasCollapsed,
|
|
1335
1360
|
version,
|
|
1336
1361
|
};
|
|
1337
1362
|
};
|
|
@@ -1341,6 +1366,7 @@ class DiffFile {
|
|
|
1341
1366
|
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, data.hasBuildSplit, "f");
|
|
1342
1367
|
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, data.hasBuildUnified, "f");
|
|
1343
1368
|
__classPrivateFieldSet(this, _DiffFile_composeByDiff, data.composeByDiff, "f");
|
|
1369
|
+
__classPrivateFieldSet(this, _DiffFile_highlighterName, data.highlighterName, "f");
|
|
1344
1370
|
__classPrivateFieldSet(this, _DiffFile_oldFileLines, data.oldFileLines, "f");
|
|
1345
1371
|
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, data.oldFileDiffLines, "f");
|
|
1346
1372
|
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, data.oldFileSyntaxLines, "f");
|
|
@@ -1351,6 +1377,7 @@ class DiffFile {
|
|
|
1351
1377
|
__classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, data.newFilePlaceholderLines, "f");
|
|
1352
1378
|
this.splitLineLength = data.splitLineLength;
|
|
1353
1379
|
this.unifiedLineLength = data.unifiedLineLength;
|
|
1380
|
+
this.hasCollapsed = data.hasCollapsed;
|
|
1354
1381
|
__classPrivateFieldSet(this, _DiffFile_splitLeftLines, data.splitLeftLines, "f");
|
|
1355
1382
|
__classPrivateFieldSet(this, _DiffFile_splitRightLines, data.splitRightLines, "f");
|
|
1356
1383
|
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, data.splitHunkLines, "f");
|
|
@@ -1361,6 +1388,7 @@ class DiffFile {
|
|
|
1361
1388
|
}
|
|
1362
1389
|
this.notifyAll();
|
|
1363
1390
|
};
|
|
1391
|
+
this._getHighlighterName = () => __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
|
|
1364
1392
|
this._getIsPureDiffRender = () => __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1365
1393
|
this._addClonedInstance = (instance) => {
|
|
1366
1394
|
const updateFunc = () => {
|
|
@@ -1469,10 +1497,12 @@ class DiffFile {
|
|
|
1469
1497
|
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeFile).call(this);
|
|
1470
1498
|
__classPrivateFieldSet(this, _DiffFile_hasInitRaw, true, "f");
|
|
1471
1499
|
}
|
|
1472
|
-
initSyntax({
|
|
1500
|
+
initSyntax({ registerHighlighter } = {}) {
|
|
1501
|
+
var _a, _b;
|
|
1473
1502
|
if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
|
|
1474
1503
|
return;
|
|
1475
|
-
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter
|
|
1504
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter });
|
|
1505
|
+
__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"), "f");
|
|
1476
1506
|
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true, "f");
|
|
1477
1507
|
}
|
|
1478
1508
|
init() {
|
|
@@ -1572,6 +1602,9 @@ class DiffFile {
|
|
|
1572
1602
|
if (!prevIsHidden && isHidden) {
|
|
1573
1603
|
hideStart = len;
|
|
1574
1604
|
}
|
|
1605
|
+
if (isHidden) {
|
|
1606
|
+
this.hasCollapsed = true;
|
|
1607
|
+
}
|
|
1575
1608
|
prevIsHidden = isHidden;
|
|
1576
1609
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
1577
1610
|
const current = newDiffLine;
|
|
@@ -1700,6 +1733,9 @@ class DiffFile {
|
|
|
1700
1733
|
if (!prevIsHidden && isHidden) {
|
|
1701
1734
|
hideStart = len;
|
|
1702
1735
|
}
|
|
1736
|
+
if (isHidden) {
|
|
1737
|
+
this.hasCollapsed = true;
|
|
1738
|
+
}
|
|
1703
1739
|
prevIsHidden = isHidden;
|
|
1704
1740
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
1705
1741
|
const current = newDiffLine;
|
|
@@ -1744,7 +1780,7 @@ class DiffFile {
|
|
|
1744
1780
|
this.notifyAll();
|
|
1745
1781
|
}
|
|
1746
1782
|
}
|
|
1747
|
-
_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_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
|
|
1783
|
+
_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_highlighterName = new WeakMap(), _DiffFile_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
|
|
1748
1784
|
if (!this._diffList)
|
|
1749
1785
|
return;
|
|
1750
1786
|
__classPrivateFieldSet(this, _DiffFile_diffListResults, this._diffList.map((s) => parseInstance.parse(s)), "f");
|
|
@@ -1939,11 +1975,11 @@ _DiffFile_oldFileResult = new WeakMap(), _DiffFile_newFileResult = new WeakMap()
|
|
|
1939
1975
|
__classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")[item.newLineNumber] = item;
|
|
1940
1976
|
}
|
|
1941
1977
|
});
|
|
1942
|
-
}, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({
|
|
1978
|
+
}, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({ registerHighlighter }) {
|
|
1943
1979
|
var _a, _b, _c, _d;
|
|
1944
|
-
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({
|
|
1980
|
+
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({ registerHighlighter });
|
|
1945
1981
|
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.syntaxFile, "f");
|
|
1946
|
-
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({
|
|
1982
|
+
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({ registerHighlighter });
|
|
1947
1983
|
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.syntaxFile, "f");
|
|
1948
1984
|
}, _DiffFile_getOldDiffLine = function _DiffFile_getOldDiffLine(lineNumber) {
|
|
1949
1985
|
var _a;
|
|
@@ -2040,7 +2076,7 @@ const getUnifiedContentLine = (diffFile) => {
|
|
|
2040
2076
|
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
2041
2077
|
};
|
|
2042
2078
|
|
|
2043
|
-
const versions = "0.0.
|
|
2079
|
+
const versions = "0.0.9";
|
|
2044
2080
|
|
|
2045
2081
|
const useUnmount = (cb, deps) => {
|
|
2046
2082
|
const ref = React.useRef(cb);
|
|
@@ -2221,14 +2257,11 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
2221
2257
|
: `var(${expandContentBGName})`;
|
|
2222
2258
|
};
|
|
2223
2259
|
|
|
2224
|
-
const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
2225
|
-
var _a, _b;
|
|
2260
|
+
const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
2226
2261
|
const { useDiffContext } = useDiffViewContext();
|
|
2227
|
-
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
2228
2262
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
2229
2263
|
const newLine = diffFile.getSplitRightLine(index);
|
|
2230
|
-
const
|
|
2231
|
-
const newLineExtend = (_b = extendData === null || extendData === void 0 ? void 0 : extendData.newFile) === null || _b === void 0 ? void 0 : _b[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber];
|
|
2264
|
+
const renderExtendLine = useDiffContext(React__namespace.useCallback((s) => s.renderExtendLine, []));
|
|
2232
2265
|
const currentExtend = side === exports.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
2233
2266
|
const currentLineNumber = side === exports.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
2234
2267
|
const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
|
|
@@ -2245,6 +2278,7 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2245
2278
|
return null;
|
|
2246
2279
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": exports.SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
2247
2280
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
2281
|
+
(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) &&
|
|
2248
2282
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
2249
2283
|
diffFile,
|
|
2250
2284
|
side,
|
|
@@ -2258,14 +2292,21 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2258
2292
|
const { useDiffContext } = useDiffViewContext();
|
|
2259
2293
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
2260
2294
|
const newLine = diffFile.getSplitRightLine(index);
|
|
2261
|
-
const
|
|
2295
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(React__namespace.useCallback((s) => {
|
|
2296
|
+
var _a, _b, _c, _d;
|
|
2297
|
+
return ({
|
|
2298
|
+
oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
|
|
2299
|
+
newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
|
|
2300
|
+
});
|
|
2301
|
+
}, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
2302
|
+
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
2262
2303
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
2263
2304
|
const enableExpand = diffFile.getExpandEnabled();
|
|
2264
2305
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
2265
2306
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
2266
2307
|
if (!currentIsShow)
|
|
2267
2308
|
return null;
|
|
2268
|
-
return React__namespace.createElement(_DiffSplitExtendLine$1, { index: index, diffFile: diffFile,
|
|
2309
|
+
return (React__namespace.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
2269
2310
|
};
|
|
2270
2311
|
|
|
2271
2312
|
const ExpandDown = ({ className }) => {
|
|
@@ -2281,6 +2322,50 @@ const ExpandAll = ({ className }) => {
|
|
|
2281
2322
|
React__namespace.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
2282
2323
|
};
|
|
2283
2324
|
|
|
2325
|
+
const removeAllSelection = () => {
|
|
2326
|
+
const selection = window.getSelection();
|
|
2327
|
+
for (let i = 0; i < selection.rangeCount; i++) {
|
|
2328
|
+
selection.removeRange(selection.getRangeAt(i));
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
const syncScroll = (left, right) => {
|
|
2332
|
+
const onScroll = function (event) {
|
|
2333
|
+
if (event === null || event.target === null)
|
|
2334
|
+
return;
|
|
2335
|
+
if (event.target === left) {
|
|
2336
|
+
right.scrollTop = left.scrollTop;
|
|
2337
|
+
right.scrollLeft = left.scrollLeft;
|
|
2338
|
+
}
|
|
2339
|
+
else {
|
|
2340
|
+
left.scrollTop = right.scrollTop;
|
|
2341
|
+
left.scrollLeft = right.scrollLeft;
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
if (!left.onscroll) {
|
|
2345
|
+
left.onscroll = onScroll;
|
|
2346
|
+
}
|
|
2347
|
+
if (!right.onscroll) {
|
|
2348
|
+
right.onscroll = onScroll;
|
|
2349
|
+
}
|
|
2350
|
+
return () => {
|
|
2351
|
+
left.onscroll = null;
|
|
2352
|
+
right.onscroll = null;
|
|
2353
|
+
};
|
|
2354
|
+
};
|
|
2355
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2356
|
+
const memoFunc = (func) => {
|
|
2357
|
+
const cache = {};
|
|
2358
|
+
return ((key) => {
|
|
2359
|
+
if (cache[key]) {
|
|
2360
|
+
return cache[key];
|
|
2361
|
+
}
|
|
2362
|
+
const result = func(key);
|
|
2363
|
+
cache[key] = result;
|
|
2364
|
+
return result;
|
|
2365
|
+
});
|
|
2366
|
+
};
|
|
2367
|
+
const asideWidth = "--diff-aside-width--";
|
|
2368
|
+
|
|
2284
2369
|
const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
2285
2370
|
var _a;
|
|
2286
2371
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
@@ -2301,6 +2386,9 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2301
2386
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
2302
2387
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
2303
2388
|
color: `var(${plainLineNumberColorName})`,
|
|
2389
|
+
width: `var(${asideWidth})`,
|
|
2390
|
+
minWidth: `var(${asideWidth})`,
|
|
2391
|
+
maxWidth: `var(${asideWidth})`,
|
|
2304
2392
|
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
2305
2393
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px] relative", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
2306
2394
|
diffFile.onSplitHunkExpand("down", index);
|
|
@@ -2333,7 +2421,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
2333
2421
|
width: "calc(var(--diff-font-size--) * 1.4)",
|
|
2334
2422
|
height: "calc(var(--diff-font-size--) * 1.4)",
|
|
2335
2423
|
} },
|
|
2336
|
-
React__namespace.createElement("button", { className: "diff-add-widget w-
|
|
2424
|
+
React__namespace.createElement("button", { className: "diff-add-widget w-full h-full invisible cursor-pointer rounded-md flex items-center justify-center transition-transform origin-center group-hover:visible hover:scale-110", style: {
|
|
2337
2425
|
color: `var(${addWidgetColorName})`,
|
|
2338
2426
|
zIndex: 1,
|
|
2339
2427
|
fontSize: `1.2em`,
|
|
@@ -2348,7 +2436,7 @@ const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget
|
|
|
2348
2436
|
width: "calc(var(--diff-font-size--) * 1.4)",
|
|
2349
2437
|
height: "calc(var(--diff-font-size--) * 1.4)",
|
|
2350
2438
|
} },
|
|
2351
|
-
React__namespace.createElement("button", { className: "diff-add-widget
|
|
2439
|
+
React__namespace.createElement("button", { className: "diff-add-widget w-full h-full invisible cursor-pointer rounded-md flex items-center justify-center transition-transform origin-center group-hover:visible hover:scale-110", style: {
|
|
2352
2440
|
color: `var(${addWidgetColorName})`,
|
|
2353
2441
|
zIndex: 1,
|
|
2354
2442
|
fontSize: `1.2em`,
|
|
@@ -2359,6 +2447,30 @@ const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget
|
|
|
2359
2447
|
} }, "+")));
|
|
2360
2448
|
};
|
|
2361
2449
|
|
|
2450
|
+
const temp = {};
|
|
2451
|
+
const formatStringToCamelCase = (str) => {
|
|
2452
|
+
const splitted = str.split("-");
|
|
2453
|
+
if (splitted.length === 1)
|
|
2454
|
+
return splitted[0];
|
|
2455
|
+
return (splitted[0] +
|
|
2456
|
+
splitted
|
|
2457
|
+
.slice(1)
|
|
2458
|
+
.map((word) => word[0].toUpperCase() + word.slice(1))
|
|
2459
|
+
.join(""));
|
|
2460
|
+
};
|
|
2461
|
+
const getStyleObjectFromString = memoFunc((str) => {
|
|
2462
|
+
if (!str)
|
|
2463
|
+
return temp;
|
|
2464
|
+
const style = {};
|
|
2465
|
+
str.split(";").forEach((el) => {
|
|
2466
|
+
const [property, value] = el.split(":");
|
|
2467
|
+
if (!property)
|
|
2468
|
+
return;
|
|
2469
|
+
const formattedProperty = formatStringToCamelCase(property.trim());
|
|
2470
|
+
style[formattedProperty] = value.trim();
|
|
2471
|
+
});
|
|
2472
|
+
return style;
|
|
2473
|
+
});
|
|
2362
2474
|
const DiffString = ({ rawLine, diffLine, operator, }) => {
|
|
2363
2475
|
const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
|
|
2364
2476
|
if (range) {
|
|
@@ -2393,9 +2505,9 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
2393
2505
|
if (range) {
|
|
2394
2506
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
2395
2507
|
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
|
|
2396
|
-
var _a, _b, _c, _d;
|
|
2508
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2397
2509
|
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
2398
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
|
|
2510
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
|
|
2399
2511
|
}
|
|
2400
2512
|
else {
|
|
2401
2513
|
const index1 = range.location - node.startIndex;
|
|
@@ -2406,7 +2518,7 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
2406
2518
|
const isStart = str1.length || range.location === node.startIndex;
|
|
2407
2519
|
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
2408
2520
|
const isNewLineSymbolChanged = range.isNewLineSymbolChanged;
|
|
2409
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (
|
|
2521
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_e = (_d = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _d === void 0 ? void 0 : _d.className) === null || _e === void 0 ? void 0 : _e.join(" "), style: getStyleObjectFromString(((_f = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _f === void 0 ? void 0 : _f.style) || "") },
|
|
2410
2522
|
str1,
|
|
2411
2523
|
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
2412
2524
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
@@ -2428,8 +2540,8 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
2428
2540
|
}))));
|
|
2429
2541
|
}
|
|
2430
2542
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" }, (_b = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _b === void 0 ? void 0 : _b.map(({ node, wrapper }, index) => {
|
|
2431
|
-
var _a, _b;
|
|
2432
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
|
|
2543
|
+
var _a, _b, _c;
|
|
2544
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
|
|
2433
2545
|
})));
|
|
2434
2546
|
};
|
|
2435
2547
|
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
@@ -2467,7 +2579,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
2467
2579
|
onAddWidgetClick: s.onAddWidgetClick,
|
|
2468
2580
|
}), []));
|
|
2469
2581
|
const { useWidget } = useDiffWidgetContext();
|
|
2470
|
-
const
|
|
2582
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
2471
2583
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
2472
2584
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
2473
2585
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
@@ -2475,8 +2587,11 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
2475
2587
|
React__namespace.createElement("td", { className: `diff-line-${exports.SplitSide[side]}-num sticky left-0 pl-[10px] pr-[10px] text-right align-top select-none w-[1%] min-w-[40px]`, style: {
|
|
2476
2588
|
backgroundColor: lineNumberBG,
|
|
2477
2589
|
color: `var(${plainLineNumberColorName})`,
|
|
2590
|
+
width: `var(${asideWidth})`,
|
|
2591
|
+
minWidth: `var(${asideWidth})`,
|
|
2592
|
+
maxWidth: `var(${asideWidth})`,
|
|
2478
2593
|
} },
|
|
2479
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2594
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2480
2595
|
React__namespace.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
2481
2596
|
React__namespace.createElement("td", { className: `diff-line-${exports.SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
2482
2597
|
React__namespace.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: `diff-line-${exports.SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
@@ -2530,37 +2645,7 @@ const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
2530
2645
|
return (React__namespace.createElement(_DiffSplitWidgetLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber, currentLine: currentLine, setWidget: setWidget, currentWidget: currentWidget }));
|
|
2531
2646
|
};
|
|
2532
2647
|
|
|
2533
|
-
|
|
2534
|
-
const selection = window.getSelection();
|
|
2535
|
-
for (let i = 0; i < selection.rangeCount; i++) {
|
|
2536
|
-
selection.removeRange(selection.getRangeAt(i));
|
|
2537
|
-
}
|
|
2538
|
-
};
|
|
2539
|
-
const syncScroll = (left, right) => {
|
|
2540
|
-
const onScroll = function (event) {
|
|
2541
|
-
if (event === null || event.target === null)
|
|
2542
|
-
return;
|
|
2543
|
-
if (event.target === left) {
|
|
2544
|
-
right.scrollTop = left.scrollTop;
|
|
2545
|
-
right.scrollLeft = left.scrollLeft;
|
|
2546
|
-
}
|
|
2547
|
-
else {
|
|
2548
|
-
left.scrollTop = right.scrollTop;
|
|
2549
|
-
left.scrollLeft = right.scrollLeft;
|
|
2550
|
-
}
|
|
2551
|
-
};
|
|
2552
|
-
if (!left.onscroll) {
|
|
2553
|
-
left.onscroll = onScroll;
|
|
2554
|
-
}
|
|
2555
|
-
if (!right.onscroll) {
|
|
2556
|
-
right.onscroll = onScroll;
|
|
2557
|
-
}
|
|
2558
|
-
return () => {
|
|
2559
|
-
left.onscroll = null;
|
|
2560
|
-
right.onscroll = null;
|
|
2561
|
-
};
|
|
2562
|
-
};
|
|
2563
|
-
|
|
2648
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2564
2649
|
const onMouseDown$1 = (e) => {
|
|
2565
2650
|
const ele = e.target;
|
|
2566
2651
|
// need remove all the selection
|
|
@@ -2569,12 +2654,12 @@ const onMouseDown$1 = (e) => {
|
|
|
2569
2654
|
return;
|
|
2570
2655
|
}
|
|
2571
2656
|
};
|
|
2572
|
-
const DiffSplitViewTable = ({ side, diffFile
|
|
2657
|
+
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
2573
2658
|
const className = side === exports.SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
2574
2659
|
const lines = getSplitContentLines(diffFile);
|
|
2575
2660
|
return (React__namespace.createElement("table", { className: className + " border-collapse w-full", "data-mode": exports.SplitSide[side] },
|
|
2576
2661
|
React__namespace.createElement("colgroup", null,
|
|
2577
|
-
React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col
|
|
2662
|
+
React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col` }),
|
|
2578
2663
|
React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-content-col` })),
|
|
2579
2664
|
React__namespace.createElement("thead", { className: "hidden" },
|
|
2580
2665
|
React__namespace.createElement("tr", null,
|
|
@@ -2606,69 +2691,81 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
2606
2691
|
return;
|
|
2607
2692
|
return syncScroll(left, right);
|
|
2608
2693
|
}, []);
|
|
2609
|
-
const
|
|
2694
|
+
const font = React__namespace.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
2695
|
+
const _width = useTextWidth({
|
|
2610
2696
|
text: splitLineLength.toString(),
|
|
2611
|
-
font
|
|
2697
|
+
font,
|
|
2612
2698
|
});
|
|
2699
|
+
const width = Math.max(40, _width + 25);
|
|
2613
2700
|
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full flex basis-[50%]" },
|
|
2614
2701
|
React__namespace.createElement("div", { className: "old-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", ref: ref1, style: {
|
|
2702
|
+
// @ts-ignore
|
|
2703
|
+
[asideWidth]: `${Math.round(width)}px`,
|
|
2615
2704
|
overscrollBehaviorX: "none",
|
|
2616
2705
|
fontFamily: "Menlo, Consolas, monospace",
|
|
2617
2706
|
fontSize: "var(--diff-font-size--)",
|
|
2618
2707
|
} },
|
|
2619
|
-
React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.old, diffFile: diffFile
|
|
2708
|
+
React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.old, diffFile: diffFile })),
|
|
2620
2709
|
React__namespace.createElement("div", { className: "diff-split-line w-[1.5px] bg-[#ccc]" }),
|
|
2621
2710
|
React__namespace.createElement("div", { className: "new-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", ref: ref2, style: {
|
|
2711
|
+
// @ts-ignore
|
|
2712
|
+
[asideWidth]: `${Math.round(width)}px`,
|
|
2622
2713
|
overscrollBehaviorX: "none",
|
|
2623
2714
|
fontFamily: "Menlo, Consolas, monospace",
|
|
2624
2715
|
fontSize: "var(--diff-font-size--)",
|
|
2625
2716
|
} },
|
|
2626
|
-
React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.new, diffFile: diffFile
|
|
2717
|
+
React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.new, diffFile: diffFile }))));
|
|
2627
2718
|
});
|
|
2628
2719
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
2629
2720
|
|
|
2630
|
-
const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2631
|
-
var _a, _b;
|
|
2721
|
+
const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
2632
2722
|
const { useDiffContext } = useDiffViewContext();
|
|
2633
|
-
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
2634
|
-
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
2635
2723
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
2636
2724
|
const newLine = diffFile.getSplitRightLine(index);
|
|
2637
|
-
|
|
2638
|
-
const
|
|
2725
|
+
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
2726
|
+
const renderExtendLine = useDiffContext(React__namespace.useCallback((s) => s.renderExtendLine, []));
|
|
2639
2727
|
if (!renderExtendLine)
|
|
2640
2728
|
return null;
|
|
2641
2729
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
2642
2730
|
oldLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
2643
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" },
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2731
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
2732
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
2733
|
+
diffFile,
|
|
2734
|
+
side: exports.SplitSide.old,
|
|
2735
|
+
lineNumber: oldLine.lineNumber,
|
|
2736
|
+
data: oldLineExtend.data,
|
|
2737
|
+
onUpdate: diffFile.notifyAll,
|
|
2738
|
+
}))))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
2650
2739
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
2651
2740
|
newLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
|
|
2652
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" },
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2741
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
2742
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
2743
|
+
diffFile,
|
|
2744
|
+
side: exports.SplitSide.new,
|
|
2745
|
+
lineNumber: newLine.lineNumber,
|
|
2746
|
+
data: newLineExtend.data,
|
|
2747
|
+
onUpdate: diffFile.notifyAll,
|
|
2748
|
+
}))))) : (React__namespace.createElement("td", { className: "diff-line-extend-new-placeholder p-0 border-l-[1px] border-l-[#ccc] select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
2659
2749
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
2660
2750
|
};
|
|
2661
2751
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2662
2752
|
const { useDiffContext } = useDiffViewContext();
|
|
2663
2753
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
2664
2754
|
const newLine = diffFile.getSplitRightLine(index);
|
|
2665
|
-
const
|
|
2755
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(React__namespace.useCallback((s) => {
|
|
2756
|
+
var _a, _b, _c, _d;
|
|
2757
|
+
return ({
|
|
2758
|
+
oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
|
|
2759
|
+
newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
|
|
2760
|
+
});
|
|
2761
|
+
}, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
2762
|
+
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
2666
2763
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
2667
2764
|
const enableExpand = diffFile.getExpandEnabled();
|
|
2668
2765
|
const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
|
|
2669
2766
|
if (!currentIsShow)
|
|
2670
2767
|
return null;
|
|
2671
|
-
return React__namespace.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
2768
|
+
return (React__namespace.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
2672
2769
|
};
|
|
2673
2770
|
|
|
2674
2771
|
const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -2688,7 +2785,7 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
2688
2785
|
if (!currentIsShow && !currentIsPureHunk)
|
|
2689
2786
|
return null;
|
|
2690
2787
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
2691
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
2788
|
+
React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none relative", style: {
|
|
2692
2789
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
2693
2790
|
color: `var(${plainLineNumberColorName})`,
|
|
2694
2791
|
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
@@ -2722,7 +2819,7 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
2722
2819
|
onAddWidgetClick: s.onAddWidgetClick,
|
|
2723
2820
|
}), []));
|
|
2724
2821
|
const { useWidget } = useDiffWidgetContext();
|
|
2725
|
-
const
|
|
2822
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
2726
2823
|
const hasOldLine = !!oldLine.lineNumber;
|
|
2727
2824
|
const hasNewLine = !!newLine.lineNumber;
|
|
2728
2825
|
const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
|
|
@@ -2732,18 +2829,18 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
2732
2829
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
2733
2830
|
hasOldLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2734
2831
|
React__namespace.createElement("td", { className: "diff-line-old-num group relative pl-[10px] pr-[10px] text-right align-top select-none w-[1%] min-w-[40px]", "data-side": exports.SplitSide[exports.SplitSide.old], style: { backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` } },
|
|
2735
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: exports.SplitSide.old, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2832
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: exports.SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2736
2833
|
React__namespace.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
2737
2834
|
React__namespace.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": exports.SplitSide[exports.SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
2738
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: exports.SplitSide.old, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute right-[100%] translate-x-[50%] z-[1] select-none", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2835
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: exports.SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] translate-x-[50%] z-[1] select-none", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2739
2836
|
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side": exports.SplitSide[exports.SplitSide.old], style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
2740
2837
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
2741
2838
|
hasNewLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2742
2839
|
React__namespace.createElement("td", { className: "diff-line-new-num group relative pl-[10px] pr-[10px] text-right align-top select-none w-[1%] min-w-[40px] border-l-[1px] border-l-[#ccc]", "data-side": exports.SplitSide[exports.SplitSide.new], style: { backgroundColor: newLineNumberBG, color: `var(${plainLineNumberColorName})` } },
|
|
2743
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.SplitSide.new, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2840
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2744
2841
|
React__namespace.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
2745
2842
|
React__namespace.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": exports.SplitSide[exports.SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
2746
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.SplitSide.new, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute right-[100%] translate-x-[50%] z-[1] select-none", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2843
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] translate-x-[50%] z-[1] select-none", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
2747
2844
|
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px] border-l-[#ccc]", style: { backgroundColor: `var(${emptyBGName})` }, "data-side": exports.SplitSide[exports.SplitSide.new], colSpan: 2 },
|
|
2748
2845
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
2749
2846
|
};
|
|
@@ -2755,15 +2852,13 @@ const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
2755
2852
|
return React__namespace.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
2756
2853
|
};
|
|
2757
2854
|
|
|
2758
|
-
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
2855
|
+
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newLineWidget, }) => {
|
|
2759
2856
|
const { useWidget } = useDiffWidgetContext();
|
|
2760
|
-
const
|
|
2857
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
2761
2858
|
const { useDiffContext } = useDiffViewContext();
|
|
2762
2859
|
const renderWidgetLine = useDiffContext(React__namespace.useCallback((s) => s.renderWidgetLine, []));
|
|
2763
2860
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
2764
2861
|
const newLine = diffFile.getSplitRightLine(index);
|
|
2765
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
2766
|
-
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
2767
2862
|
if (!renderWidgetLine)
|
|
2768
2863
|
return null;
|
|
2769
2864
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
@@ -2794,7 +2889,7 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
2794
2889
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
2795
2890
|
if (!currentIsShow)
|
|
2796
2891
|
return null;
|
|
2797
|
-
return React__namespace.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
2892
|
+
return (React__namespace.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineWidget: oldLineWidget, newLineWidget: newLineWidget }));
|
|
2798
2893
|
};
|
|
2799
2894
|
|
|
2800
2895
|
const Style = ({ useSelector, id, }) => {
|
|
@@ -2838,10 +2933,12 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
2838
2933
|
}
|
|
2839
2934
|
}
|
|
2840
2935
|
}, [setSelectSide]);
|
|
2841
|
-
const
|
|
2936
|
+
const font = React.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
2937
|
+
const _width = useTextWidth({
|
|
2842
2938
|
text: splitLineLength.toString(),
|
|
2843
|
-
font
|
|
2939
|
+
font,
|
|
2844
2940
|
});
|
|
2941
|
+
const width = Math.max(40, _width + 25);
|
|
2845
2942
|
const lines = getSplitContentLines(diffFile);
|
|
2846
2943
|
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
|
|
2847
2944
|
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
@@ -2851,9 +2948,9 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
2851
2948
|
React__namespace.createElement(Style, { useSelector: splitSideInfo, id: `diff-root${diffFile.getId()}` }),
|
|
2852
2949
|
React__namespace.createElement("table", { className: "diff-table border-collapse table-fixed w-full" },
|
|
2853
2950
|
React__namespace.createElement("colgroup", null,
|
|
2854
|
-
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width)
|
|
2951
|
+
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
2855
2952
|
React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
|
|
2856
|
-
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width)
|
|
2953
|
+
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
2857
2954
|
React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
|
|
2858
2955
|
React__namespace.createElement("thead", { className: "hidden" },
|
|
2859
2956
|
React__namespace.createElement("tr", null,
|
|
@@ -2888,7 +2985,6 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
2888
2985
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
2889
2986
|
}), [useDiffContext]);
|
|
2890
2987
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
2891
|
-
shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
2892
2988
|
React.useEffect(() => {
|
|
2893
2989
|
const { setWidget } = useWidget.getReadonlyState();
|
|
2894
2990
|
setWidget({});
|
|
@@ -2897,12 +2993,10 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
2897
2993
|
});
|
|
2898
2994
|
DiffSplitView.displayName = "DiffSplitView";
|
|
2899
2995
|
|
|
2900
|
-
const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2996
|
+
const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
2901
2997
|
const { useDiffContext } = useDiffViewContext();
|
|
2902
2998
|
const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
|
|
2903
2999
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
2904
|
-
const oldExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]));
|
|
2905
|
-
const newExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.newFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]));
|
|
2906
3000
|
const width = useDomWidth({
|
|
2907
3001
|
selector: ".unified-diff-table-wrapper",
|
|
2908
3002
|
enable: typeof renderExtendLine === "function",
|
|
@@ -2913,31 +3007,38 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
2913
3007
|
React__namespace.createElement("td", { className: "diff-line-extend-content align-top p-0", colSpan: 2 },
|
|
2914
3008
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
2915
3009
|
width > 0 &&
|
|
2916
|
-
|
|
3010
|
+
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
2917
3011
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
2918
3012
|
diffFile,
|
|
2919
3013
|
side: exports.SplitSide.old,
|
|
2920
3014
|
lineNumber: unifiedItem.oldLineNumber,
|
|
2921
|
-
data:
|
|
3015
|
+
data: oldLineExtend.data,
|
|
2922
3016
|
onUpdate: diffFile.notifyAll,
|
|
2923
3017
|
})),
|
|
2924
3018
|
width > 0 &&
|
|
2925
|
-
|
|
3019
|
+
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
2926
3020
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
2927
3021
|
diffFile,
|
|
2928
3022
|
side: exports.SplitSide.new,
|
|
2929
3023
|
lineNumber: unifiedItem.newLineNumber,
|
|
2930
|
-
data:
|
|
3024
|
+
data: newLineExtend.data,
|
|
2931
3025
|
onUpdate: diffFile.notifyAll,
|
|
2932
3026
|
}))))));
|
|
2933
3027
|
};
|
|
2934
3028
|
const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2935
3029
|
const { useDiffContext } = useDiffViewContext();
|
|
2936
3030
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
2937
|
-
const
|
|
3031
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(React.useCallback((s) => {
|
|
3032
|
+
var _a, _b, _c, _d;
|
|
3033
|
+
return ({
|
|
3034
|
+
oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber],
|
|
3035
|
+
newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber],
|
|
3036
|
+
});
|
|
3037
|
+
}, [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
|
|
3038
|
+
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
2938
3039
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden || !unifiedItem.diff)
|
|
2939
3040
|
return null;
|
|
2940
|
-
return React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
3041
|
+
return (React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
2941
3042
|
};
|
|
2942
3043
|
|
|
2943
3044
|
const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -2956,6 +3057,9 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
2956
3057
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
|
|
2957
3058
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
2958
3059
|
color: `var(${plainLineNumberColorName})`,
|
|
3060
|
+
width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3061
|
+
maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3062
|
+
minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
2959
3063
|
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
|
|
2960
3064
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
|
|
2961
3065
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
|
|
@@ -2987,6 +3091,9 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
2987
3091
|
React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
|
|
2988
3092
|
color: `var(${plainLineNumberColorName})`,
|
|
2989
3093
|
backgroundColor: `var(${delLineNumberBGName})`,
|
|
3094
|
+
width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3095
|
+
maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3096
|
+
minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
2990
3097
|
} },
|
|
2991
3098
|
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: exports.SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
2992
3099
|
React__namespace.createElement("div", { className: "flex" },
|
|
@@ -3001,6 +3108,9 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
3001
3108
|
React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
|
|
3002
3109
|
color: `var(${plainLineNumberColorName})`,
|
|
3003
3110
|
backgroundColor: `var(${addLineNumberBGName})`,
|
|
3111
|
+
width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3112
|
+
maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3113
|
+
minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3004
3114
|
} },
|
|
3005
3115
|
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: exports.SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
3006
3116
|
React__namespace.createElement("div", { className: "flex" },
|
|
@@ -3020,7 +3130,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
3020
3130
|
onAddWidgetClick: s.onAddWidgetClick,
|
|
3021
3131
|
}), []));
|
|
3022
3132
|
const { useWidget } = useDiffWidgetContext();
|
|
3023
|
-
const
|
|
3133
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
3024
3134
|
const hasDiff = unifiedLine.diff;
|
|
3025
3135
|
const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
|
|
3026
3136
|
const rawLine = unifiedLine.value || "";
|
|
@@ -3034,19 +3144,22 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
3034
3144
|
: undefined;
|
|
3035
3145
|
if (hasChange) {
|
|
3036
3146
|
if (unifiedLine.oldLineNumber) {
|
|
3037
|
-
return (React__namespace.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, onAddWidgetClick: onAddWidgetClick
|
|
3147
|
+
return (React__namespace.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.oldLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
3038
3148
|
}
|
|
3039
3149
|
else {
|
|
3040
|
-
return (React__namespace.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, onAddWidgetClick: onAddWidgetClick
|
|
3150
|
+
return (React__namespace.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.newLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
3041
3151
|
}
|
|
3042
3152
|
}
|
|
3043
3153
|
else {
|
|
3044
3154
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
3045
3155
|
React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
|
|
3046
3156
|
color: `var(${plainLineNumberColorName})`,
|
|
3157
|
+
width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3158
|
+
maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3159
|
+
minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
|
|
3047
3160
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
3048
3161
|
} },
|
|
3049
|
-
enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: exports.SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
3162
|
+
enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: exports.SplitSide.new, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
3050
3163
|
React__namespace.createElement("div", { className: "flex opacity-[0.5]" },
|
|
3051
3164
|
React__namespace.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
3052
3165
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
@@ -3099,6 +3212,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3099
3212
|
return (React__namespace.createElement(_DiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldWidget: oldWidget, newWidget: newWidget, setWidget: setWidget }));
|
|
3100
3213
|
};
|
|
3101
3214
|
|
|
3215
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3102
3216
|
const onMouseDown = (e) => {
|
|
3103
3217
|
const ele = e.target;
|
|
3104
3218
|
// need remove all the selection
|
|
@@ -3123,15 +3237,27 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
3123
3237
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
3124
3238
|
}), [useDiffContext]);
|
|
3125
3239
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
3240
|
+
const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
|
|
3126
3241
|
shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
3127
3242
|
React.useEffect(() => {
|
|
3128
3243
|
const { setWidget } = useWidget.getReadonlyState();
|
|
3129
3244
|
setWidget({});
|
|
3130
3245
|
}, [diffFile, useWidget]);
|
|
3246
|
+
const unifiedLineLength = diffFile.unifiedLineLength;
|
|
3247
|
+
const _width = useTextWidth({
|
|
3248
|
+
text: unifiedLineLength.toString(),
|
|
3249
|
+
font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
|
|
3250
|
+
});
|
|
3251
|
+
const width = Math.max(40, _width + 25);
|
|
3131
3252
|
const lines = getUnifiedContentLine(diffFile);
|
|
3132
3253
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
3133
3254
|
React__namespace.createElement("div", { className: "unified-diff-view w-full" },
|
|
3134
|
-
React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", style: {
|
|
3255
|
+
React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", style: {
|
|
3256
|
+
// @ts-ignore
|
|
3257
|
+
[asideWidth]: `${Math.round(width)}px`,
|
|
3258
|
+
fontFamily: "Menlo, Consolas, monospace",
|
|
3259
|
+
fontSize: "var(--diff-font-size--)",
|
|
3260
|
+
} },
|
|
3135
3261
|
React__namespace.createElement("table", { className: "unified-diff-table border-collapse w-full" },
|
|
3136
3262
|
React__namespace.createElement("colgroup", null,
|
|
3137
3263
|
React__namespace.createElement("col", { className: "unified-diff-table-num-col" }),
|
|
@@ -3140,7 +3266,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
3140
3266
|
React__namespace.createElement("tr", null,
|
|
3141
3267
|
React__namespace.createElement("th", { scope: "col" }, "line number"),
|
|
3142
3268
|
React__namespace.createElement("th", { scope: "col" }, "line content"))),
|
|
3143
|
-
React__namespace.createElement("tbody", { className: "diff-table-body
|
|
3269
|
+
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
3144
3270
|
lines.map((item) => (React__namespace.createElement(React.Fragment, { key: item.index },
|
|
3145
3271
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
3146
3272
|
React__namespace.createElement(DiffUnifiedLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
@@ -3205,8 +3331,9 @@ const _InternalDiffView = (props) => {
|
|
|
3205
3331
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
3206
3332
|
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
3207
3333
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
3208
|
-
|
|
3209
|
-
const
|
|
3334
|
+
// 避免无意义的订阅
|
|
3335
|
+
const onAddWidgetClick = reactivityStore.ref(reactivityStore.markRaw({ current: props.onAddWidgetClick }));
|
|
3336
|
+
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.value.current = _onAddWidgetClick.current);
|
|
3210
3337
|
return {
|
|
3211
3338
|
id,
|
|
3212
3339
|
setId,
|
|
@@ -3241,7 +3368,7 @@ const _InternalDiffView = (props) => {
|
|
|
3241
3368
|
diffViewWrap !== enableWrap && setEnableWrap(diffViewWrap);
|
|
3242
3369
|
extendData && setExtendData(extendData);
|
|
3243
3370
|
diffViewFontSize && diffViewFontSize !== fontSize && setFontSize(diffViewFontSize);
|
|
3244
|
-
onAddWidgetClick !== _onAddWidgetClick && setOnAddWidgetClick(onAddWidgetClick);
|
|
3371
|
+
onAddWidgetClick !== _onAddWidgetClick.current && setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
3245
3372
|
renderExtendLine !== _renderExtendLine && setRenderExtendLine(renderExtendLine);
|
|
3246
3373
|
renderWidgetLine !== _renderWidgetLine && setRenderWidgetLine(renderWidgetLine);
|
|
3247
3374
|
}, [
|
|
@@ -3259,7 +3386,7 @@ const _InternalDiffView = (props) => {
|
|
|
3259
3386
|
]);
|
|
3260
3387
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
3261
3388
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
3262
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.
|
|
3389
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.9"}`, "data-highlighter": diffFile._getHighlighterName() },
|
|
3263
3390
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
3264
3391
|
// @ts-ignore
|
|
3265
3392
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -3268,7 +3395,7 @@ const _InternalDiffView = (props) => {
|
|
|
3268
3395
|
};
|
|
3269
3396
|
const InternalDiffView = React.memo(_InternalDiffView);
|
|
3270
3397
|
const DiffViewWithRef = (props, ref) => {
|
|
3271
|
-
const { registerHighlighter,
|
|
3398
|
+
const { registerHighlighter, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffFile"]);
|
|
3272
3399
|
const diffFile = React.useMemo(() => {
|
|
3273
3400
|
var _a, _b, _c, _d, _e, _f;
|
|
3274
3401
|
if (_diffFile) {
|
|
@@ -3292,10 +3419,10 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
3292
3419
|
if (!diffFile)
|
|
3293
3420
|
return;
|
|
3294
3421
|
if (props.diffViewHighlight) {
|
|
3295
|
-
diffFile.initSyntax({
|
|
3422
|
+
diffFile.initSyntax({ registerHighlighter });
|
|
3296
3423
|
diffFile.notifyAll();
|
|
3297
3424
|
}
|
|
3298
|
-
}, [diffFile, props.diffViewHighlight,
|
|
3425
|
+
}, [diffFile, props.diffViewHighlight, registerHighlighter]);
|
|
3299
3426
|
React.useEffect(() => {
|
|
3300
3427
|
if (_diffFile && diffFile) {
|
|
3301
3428
|
_diffFile._addClonedInstance(diffFile);
|
|
@@ -3312,7 +3439,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
3312
3439
|
};
|
|
3313
3440
|
const DiffView = React.forwardRef(DiffViewWithRef);
|
|
3314
3441
|
DiffView.displayName = "DiffView";
|
|
3315
|
-
const version = "0.0.
|
|
3442
|
+
const version = "0.0.9";
|
|
3316
3443
|
|
|
3317
3444
|
exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
|
|
3318
3445
|
exports.DiffFile = DiffFile;
|
|
@@ -3336,6 +3463,7 @@ exports.getUnifiedLines = getUnifiedLines;
|
|
|
3336
3463
|
exports.hasRelativeChange = hasRelativeChange;
|
|
3337
3464
|
exports.highlighter = highlighter;
|
|
3338
3465
|
exports.numIterator = numIterator;
|
|
3466
|
+
exports.processAST = processAST;
|
|
3339
3467
|
exports.relativeChanges = relativeChanges;
|
|
3340
3468
|
exports.useDiffViewContext = useDiffViewContext;
|
|
3341
3469
|
exports.version = version;
|