@git-diff-view/react 0.0.36 → 0.0.38
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 +36 -109
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +36 -109
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +0 -3
- package/dist/css/diff-view.css +0 -3
- package/dist/esm/index.mjs +37 -110
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +12 -9
- package/package.json +2 -2
- package/src/components/DiffContent.tsx +15 -161
- package/src/components/DiffUnifiedContentLine.tsx +117 -122
- package/src/components/DiffView.tsx +14 -5
- package/styles/diff-view-pure.css +0 -3
- package/styles/diff-view.css +0 -3
package/index.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ declare class File$1 {
|
|
|
28
28
|
highlighterName?: DiffHighlighter["name"];
|
|
29
29
|
highlighterType?: DiffHighlighter["type"];
|
|
30
30
|
maxLineNumber: number;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated
|
|
33
|
+
*/
|
|
31
34
|
enableTemplate: boolean;
|
|
32
35
|
static createInstance(data: File$1): File$1;
|
|
33
36
|
constructor(row: string, lang: DiffHighlighterLang, fileName?: string);
|
|
@@ -111,12 +114,9 @@ export declare class DiffFile {
|
|
|
111
114
|
initTheme(theme?: "light" | "dark"): void;
|
|
112
115
|
initRaw(): void;
|
|
113
116
|
initSyntax({ registerHighlighter }?: {
|
|
114
|
-
registerHighlighter?:
|
|
117
|
+
registerHighlighter?: DiffFileHighlighter;
|
|
115
118
|
}): void;
|
|
116
119
|
init(): void;
|
|
117
|
-
enableTemplate(): void;
|
|
118
|
-
disableTemplate(): void;
|
|
119
|
-
getIsEnableTemplate(): boolean;
|
|
120
120
|
buildSplitDiffLines(): void;
|
|
121
121
|
buildUnifiedDiffLines(): void;
|
|
122
122
|
getSplitLeftLine: (index: number) => SplitLineItem;
|
|
@@ -203,11 +203,11 @@ export declare class DiffFile {
|
|
|
203
203
|
};
|
|
204
204
|
version: string;
|
|
205
205
|
theme: "light" | "dark";
|
|
206
|
-
enableTemplate: boolean;
|
|
207
206
|
isFullMerge: boolean;
|
|
208
207
|
};
|
|
209
208
|
mergeBundle: (data: ReturnType<DiffFile["getBundle"]>, notifyUpdate?: boolean) => void;
|
|
210
209
|
_getHighlighterName: () => string;
|
|
210
|
+
_getHighlighterType: () => string;
|
|
211
211
|
_getIsPureDiffRender: () => boolean;
|
|
212
212
|
_getTheme: () => "light" | "dark";
|
|
213
213
|
_addClonedInstance: (instance: DiffFile) => void;
|
|
@@ -265,7 +265,6 @@ export declare class DiffFile {
|
|
|
265
265
|
};
|
|
266
266
|
version: string;
|
|
267
267
|
theme: "light" | "dark";
|
|
268
|
-
enableTemplate: boolean;
|
|
269
268
|
};
|
|
270
269
|
_mergeFullBundle: (data: ReturnType<DiffFile["_getFullBundle"]>, notifyUpdate?: boolean) => void;
|
|
271
270
|
_destroy: () => void;
|
|
@@ -317,8 +316,9 @@ export declare class DiffLine {
|
|
|
317
316
|
plainTemplate?: string;
|
|
318
317
|
plainTemplateMode?: "fast-diff" | "relative";
|
|
319
318
|
syntaxTemplate?: string;
|
|
319
|
+
syntaxTemplateName?: string;
|
|
320
320
|
syntaxTemplateMode?: "fast-diff" | "relative";
|
|
321
|
-
constructor(text: string, type: DiffLineType, originalLineNumber: number | null, oldLineNumber: number | null, newLineNumber: number | null, noTrailingNewLine?: boolean, changes?: IRange, diffChanges?: DiffRange, _diffChanges?: DiffRange, plainTemplate?: string, plainTemplateMode?: "fast-diff" | "relative", syntaxTemplate?: string, syntaxTemplateMode?: "fast-diff" | "relative");
|
|
321
|
+
constructor(text: string, type: DiffLineType, originalLineNumber: number | null, oldLineNumber: number | null, newLineNumber: number | null, noTrailingNewLine?: boolean, changes?: IRange, diffChanges?: DiffRange, _diffChanges?: DiffRange, plainTemplate?: string, plainTemplateMode?: "fast-diff" | "relative", syntaxTemplate?: string, syntaxTemplateName?: string, syntaxTemplateMode?: "fast-diff" | "relative");
|
|
322
322
|
withNoTrailingNewLine(noTrailingNewLine: boolean): DiffLine;
|
|
323
323
|
isIncludeableLine(): boolean;
|
|
324
324
|
equals(other: DiffLine): boolean;
|
|
@@ -484,12 +484,14 @@ export declare const getPlainDiffTemplateByFastDiff: ({ diffLine, rawLine, opera
|
|
|
484
484
|
export declare const getPlainLineTemplate: (line: string) => string;
|
|
485
485
|
export declare const getSplitContentLines: (diffFile: DiffFile) => DiffSplitContentLineItem[];
|
|
486
486
|
export declare const getSplitLines: (diffFile: DiffFile) => DiffSplitLineItem[];
|
|
487
|
-
export declare const getSyntaxDiffTemplate: ({ diffLine, syntaxLine, operator, }: {
|
|
487
|
+
export declare const getSyntaxDiffTemplate: ({ diffFile, diffLine, syntaxLine, operator, }: {
|
|
488
|
+
diffFile: DiffFile;
|
|
488
489
|
diffLine: DiffLine;
|
|
489
490
|
syntaxLine: SyntaxLine;
|
|
490
491
|
operator: "add" | "del";
|
|
491
492
|
}) => void;
|
|
492
|
-
export declare const getSyntaxDiffTemplateByFastDiff: ({ diffLine, syntaxLine, operator, }: {
|
|
493
|
+
export declare const getSyntaxDiffTemplateByFastDiff: ({ diffFile, diffLine, syntaxLine, operator, }: {
|
|
494
|
+
diffFile: DiffFile;
|
|
493
495
|
diffLine: DiffLine;
|
|
494
496
|
syntaxLine: SyntaxLine;
|
|
495
497
|
operator: "add" | "del";
|
|
@@ -716,6 +718,7 @@ export interface UnifiedLineItem {
|
|
|
716
718
|
_isHidden?: boolean;
|
|
717
719
|
}
|
|
718
720
|
export type DiffAST = Root;
|
|
721
|
+
export type DiffFileHighlighter = Omit<DiffHighlighter, "getHighlighterEngine">;
|
|
719
722
|
export type DiffHighlighter = {
|
|
720
723
|
name: string;
|
|
721
724
|
type: "class" | "style" | string;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "@git-diff-view/react",
|
|
4
4
|
"author": "MrWangJustToDo",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.38",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"types": "index.d.ts",
|
|
9
9
|
"files": [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react diff component"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@git-diff-view/core": "^0.0.
|
|
64
|
+
"@git-diff-view/core": "^0.0.38",
|
|
65
65
|
"@types/hast": "^3.0.0",
|
|
66
66
|
"fast-diff": "^1.3.0",
|
|
67
67
|
"highlight.js": "^11.11.0",
|
|
@@ -6,14 +6,7 @@ import {
|
|
|
6
6
|
getPlainDiffTemplate,
|
|
7
7
|
getPlainLineTemplate,
|
|
8
8
|
} from "@git-diff-view/core";
|
|
9
|
-
import {
|
|
10
|
-
memoFunc,
|
|
11
|
-
addContentHighlightBGName,
|
|
12
|
-
delContentHighlightBGName,
|
|
13
|
-
diffFontSizeName,
|
|
14
|
-
getSymbol,
|
|
15
|
-
NewLineSymbol,
|
|
16
|
-
} from "@git-diff-view/utils";
|
|
9
|
+
import { memoFunc, diffFontSizeName, NewLineSymbol } from "@git-diff-view/utils";
|
|
17
10
|
import * as React from "react";
|
|
18
11
|
|
|
19
12
|
import { DiffNoNewLine } from "./DiffNoNewLine";
|
|
@@ -54,25 +47,23 @@ const DiffString = ({
|
|
|
54
47
|
operator,
|
|
55
48
|
plainLine,
|
|
56
49
|
enableWrap,
|
|
57
|
-
enableTemplate,
|
|
58
50
|
}: {
|
|
59
51
|
rawLine: string;
|
|
60
52
|
diffLine?: DiffLine;
|
|
61
53
|
operator?: "add" | "del";
|
|
62
54
|
plainLine?: File["plainFile"][number];
|
|
63
55
|
enableWrap?: boolean;
|
|
64
|
-
enableTemplate?: boolean;
|
|
65
56
|
}) => {
|
|
66
57
|
const changes = diffLine?.changes;
|
|
67
58
|
|
|
68
59
|
if (changes?.hasLineChange) {
|
|
69
60
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
70
61
|
|
|
71
|
-
if (
|
|
62
|
+
if (!diffLine?.plainTemplate && typeof getPlainDiffTemplate === "function") {
|
|
72
63
|
getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
if (
|
|
66
|
+
if (diffLine?.plainTemplate) {
|
|
76
67
|
return (
|
|
77
68
|
<span className="diff-line-content-raw">
|
|
78
69
|
<span data-template dangerouslySetInnerHTML={{ __html: diffLine.plainTemplate }} />
|
|
@@ -90,59 +81,14 @@ const DiffString = ({
|
|
|
90
81
|
)}
|
|
91
82
|
</span>
|
|
92
83
|
);
|
|
93
|
-
} else {
|
|
94
|
-
// TODO remove
|
|
95
|
-
const range = changes.range;
|
|
96
|
-
const str1 = rawLine.slice(0, range.location);
|
|
97
|
-
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
98
|
-
const str3 = rawLine.slice(range.location + range.length);
|
|
99
|
-
const isLast = str2.includes("\n");
|
|
100
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
101
|
-
return (
|
|
102
|
-
<span className="diff-line-content-raw">
|
|
103
|
-
<span data-range-start={range.location} data-range-end={range.location + range.length}>
|
|
104
|
-
{str1}
|
|
105
|
-
<span
|
|
106
|
-
data-diff-highlight
|
|
107
|
-
className="rounded-[0.2em]"
|
|
108
|
-
style={{
|
|
109
|
-
backgroundColor:
|
|
110
|
-
operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
111
|
-
}}
|
|
112
|
-
>
|
|
113
|
-
{isLast ? (
|
|
114
|
-
<>
|
|
115
|
-
{_str2}
|
|
116
|
-
<span data-newline-symbol>{getSymbol(isNewLineSymbolChanged)}</span>
|
|
117
|
-
</>
|
|
118
|
-
) : (
|
|
119
|
-
str2
|
|
120
|
-
)}
|
|
121
|
-
</span>
|
|
122
|
-
{str3}
|
|
123
|
-
</span>
|
|
124
|
-
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
|
|
125
|
-
<span
|
|
126
|
-
data-no-newline-at-end-of-file-symbol
|
|
127
|
-
className={enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500"}
|
|
128
|
-
style={{
|
|
129
|
-
width: `var(${diffFontSizeName})`,
|
|
130
|
-
height: `var(${diffFontSizeName})`,
|
|
131
|
-
}}
|
|
132
|
-
>
|
|
133
|
-
<DiffNoNewLine />
|
|
134
|
-
</span>
|
|
135
|
-
)}
|
|
136
|
-
</span>
|
|
137
|
-
);
|
|
138
84
|
}
|
|
139
85
|
}
|
|
140
86
|
|
|
141
|
-
if (
|
|
87
|
+
if (plainLine && !plainLine?.template) {
|
|
142
88
|
plainLine.template = getPlainLineTemplate(plainLine.value);
|
|
143
89
|
}
|
|
144
90
|
|
|
145
|
-
if (
|
|
91
|
+
if (plainLine?.template) {
|
|
146
92
|
return (
|
|
147
93
|
<span className="diff-line-content-raw">
|
|
148
94
|
<span data-template dangerouslySetInnerHTML={{ __html: plainLine.template }} />
|
|
@@ -155,29 +101,21 @@ const DiffString = ({
|
|
|
155
101
|
|
|
156
102
|
const DiffSyntax = ({
|
|
157
103
|
rawLine,
|
|
104
|
+
diffFile,
|
|
158
105
|
diffLine,
|
|
159
106
|
operator,
|
|
160
107
|
syntaxLine,
|
|
161
108
|
enableWrap,
|
|
162
|
-
enableTemplate,
|
|
163
109
|
}: {
|
|
164
110
|
rawLine: string;
|
|
111
|
+
diffFile: DiffFile;
|
|
165
112
|
diffLine?: DiffLine;
|
|
166
113
|
syntaxLine?: File["syntaxFile"][number];
|
|
167
114
|
operator?: "add" | "del";
|
|
168
115
|
enableWrap?: boolean;
|
|
169
|
-
enableTemplate?: boolean;
|
|
170
116
|
}) => {
|
|
171
117
|
if (!syntaxLine) {
|
|
172
|
-
return
|
|
173
|
-
<DiffString
|
|
174
|
-
rawLine={rawLine}
|
|
175
|
-
diffLine={diffLine}
|
|
176
|
-
operator={operator}
|
|
177
|
-
enableWrap={enableWrap}
|
|
178
|
-
enableTemplate={enableTemplate}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
118
|
+
return <DiffString rawLine={rawLine} diffLine={diffLine} operator={operator} enableWrap={enableWrap} />;
|
|
181
119
|
}
|
|
182
120
|
|
|
183
121
|
const changes = diffLine?.changes;
|
|
@@ -185,11 +123,11 @@ const DiffSyntax = ({
|
|
|
185
123
|
if (changes?.hasLineChange) {
|
|
186
124
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
187
125
|
|
|
188
|
-
if (
|
|
189
|
-
getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
126
|
+
if (!diffLine?.syntaxTemplate && typeof getSyntaxDiffTemplate === "function") {
|
|
127
|
+
getSyntaxDiffTemplate({ diffFile, diffLine, syntaxLine, operator });
|
|
190
128
|
}
|
|
191
129
|
|
|
192
|
-
if (
|
|
130
|
+
if (diffLine?.syntaxTemplate) {
|
|
193
131
|
return (
|
|
194
132
|
<span className="diff-line-syntax-raw">
|
|
195
133
|
<span data-template dangerouslySetInnerHTML={{ __html: diffLine.syntaxTemplate }} />
|
|
@@ -207,95 +145,14 @@ const DiffSyntax = ({
|
|
|
207
145
|
)}
|
|
208
146
|
</span>
|
|
209
147
|
);
|
|
210
|
-
} else {
|
|
211
|
-
// TODO remove
|
|
212
|
-
const range = changes.range;
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<span className="diff-line-syntax-raw">
|
|
216
|
-
<span data-range-start={range.location} data-range-end={range.location + range.length}>
|
|
217
|
-
{syntaxLine.nodeList?.map(({ node, wrapper }, index) => {
|
|
218
|
-
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
219
|
-
return (
|
|
220
|
-
<span
|
|
221
|
-
key={index}
|
|
222
|
-
data-start={node.startIndex}
|
|
223
|
-
data-end={node.endIndex}
|
|
224
|
-
className={wrapper?.properties?.className?.join(" ")}
|
|
225
|
-
style={getStyleObjectFromString(wrapper?.properties?.style || "")}
|
|
226
|
-
>
|
|
227
|
-
{node.value}
|
|
228
|
-
</span>
|
|
229
|
-
);
|
|
230
|
-
} else {
|
|
231
|
-
const index1 = range.location - node.startIndex;
|
|
232
|
-
const index2 = index1 < 0 ? 0 : index1;
|
|
233
|
-
const str1 = node.value.slice(0, index2);
|
|
234
|
-
const str2 = node.value.slice(index2, index1 + range.length);
|
|
235
|
-
const str3 = node.value.slice(index1 + range.length);
|
|
236
|
-
const isStart = str1.length || range.location === node.startIndex;
|
|
237
|
-
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
238
|
-
const isLast = str2.includes("\n");
|
|
239
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
240
|
-
return (
|
|
241
|
-
<span
|
|
242
|
-
key={index}
|
|
243
|
-
data-start={node.startIndex}
|
|
244
|
-
data-end={node.endIndex}
|
|
245
|
-
className={wrapper?.properties?.className?.join(" ")}
|
|
246
|
-
style={getStyleObjectFromString(wrapper?.properties?.style || "")}
|
|
247
|
-
>
|
|
248
|
-
{str1}
|
|
249
|
-
<span
|
|
250
|
-
data-diff-highlight
|
|
251
|
-
style={{
|
|
252
|
-
backgroundColor:
|
|
253
|
-
operator === "add"
|
|
254
|
-
? `var(${addContentHighlightBGName})`
|
|
255
|
-
: `var(${delContentHighlightBGName})`,
|
|
256
|
-
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
257
|
-
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
258
|
-
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
259
|
-
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
260
|
-
}}
|
|
261
|
-
>
|
|
262
|
-
{isLast ? (
|
|
263
|
-
<>
|
|
264
|
-
{_str2}
|
|
265
|
-
<span data-newline-symbol>{getSymbol(isNewLineSymbolChanged)}</span>
|
|
266
|
-
</>
|
|
267
|
-
) : (
|
|
268
|
-
str2
|
|
269
|
-
)}
|
|
270
|
-
</span>
|
|
271
|
-
{str3}
|
|
272
|
-
</span>
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
})}
|
|
276
|
-
</span>
|
|
277
|
-
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
|
|
278
|
-
<span
|
|
279
|
-
data-no-newline-at-end-of-file-symbol
|
|
280
|
-
className={enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500"}
|
|
281
|
-
style={{
|
|
282
|
-
width: `var(${diffFontSizeName})`,
|
|
283
|
-
height: `var(${diffFontSizeName})`,
|
|
284
|
-
}}
|
|
285
|
-
>
|
|
286
|
-
<DiffNoNewLine />
|
|
287
|
-
</span>
|
|
288
|
-
)}
|
|
289
|
-
</span>
|
|
290
|
-
);
|
|
291
148
|
}
|
|
292
149
|
}
|
|
293
150
|
|
|
294
|
-
if (
|
|
151
|
+
if (!syntaxLine.template) {
|
|
295
152
|
syntaxLine.template = getSyntaxLineTemplate(syntaxLine);
|
|
296
153
|
}
|
|
297
154
|
|
|
298
|
-
if (
|
|
155
|
+
if (syntaxLine?.template) {
|
|
299
156
|
return (
|
|
300
157
|
<span className="diff-line-syntax-raw">
|
|
301
158
|
<span data-template dangerouslySetInnerHTML={{ __html: syntaxLine.template }} />
|
|
@@ -321,8 +178,8 @@ const DiffSyntax = ({
|
|
|
321
178
|
};
|
|
322
179
|
|
|
323
180
|
export const DiffContent = ({
|
|
324
|
-
diffLine,
|
|
325
181
|
diffFile,
|
|
182
|
+
diffLine,
|
|
326
183
|
rawLine,
|
|
327
184
|
plainLine,
|
|
328
185
|
syntaxLine,
|
|
@@ -343,8 +200,6 @@ export const DiffContent = ({
|
|
|
343
200
|
|
|
344
201
|
const isMaxLineLengthToIgnoreSyntax = syntaxLine?.nodeList?.length > 150;
|
|
345
202
|
|
|
346
|
-
const isEnableTemplate = diffFile.getIsEnableTemplate?.() ?? true;
|
|
347
|
-
|
|
348
203
|
return (
|
|
349
204
|
<div
|
|
350
205
|
className="diff-line-content-item pl-[2.0em]"
|
|
@@ -364,10 +219,10 @@ export const DiffContent = ({
|
|
|
364
219
|
<DiffSyntax
|
|
365
220
|
operator={isAdded ? "add" : isDelete ? "del" : undefined}
|
|
366
221
|
rawLine={rawLine}
|
|
222
|
+
diffFile={diffFile}
|
|
367
223
|
diffLine={diffLine}
|
|
368
224
|
syntaxLine={syntaxLine}
|
|
369
225
|
enableWrap={enableWrap}
|
|
370
|
-
enableTemplate={isEnableTemplate}
|
|
371
226
|
/>
|
|
372
227
|
) : (
|
|
373
228
|
<DiffString
|
|
@@ -376,7 +231,6 @@ export const DiffContent = ({
|
|
|
376
231
|
diffLine={diffLine}
|
|
377
232
|
plainLine={plainLine}
|
|
378
233
|
enableWrap={enableWrap}
|
|
379
|
-
enableTemplate={isEnableTemplate}
|
|
380
234
|
/>
|
|
381
235
|
)}
|
|
382
236
|
</div>
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
expandLineNumberColorName,
|
|
13
13
|
} from "@git-diff-view/utils";
|
|
14
14
|
import * as React from "react";
|
|
15
|
-
import { memo } from "react";
|
|
16
15
|
|
|
17
16
|
import { SplitSide } from "..";
|
|
18
17
|
|
|
@@ -167,148 +166,144 @@ const DiffUnifiedNewLine = ({
|
|
|
167
166
|
);
|
|
168
167
|
};
|
|
169
168
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
169
|
+
const InternalDiffUnifiedLine = ({
|
|
170
|
+
index,
|
|
171
|
+
diffFile,
|
|
172
|
+
lineNumber,
|
|
173
|
+
enableWrap,
|
|
174
|
+
enableAddWidget,
|
|
175
|
+
enableHighlight,
|
|
176
|
+
}: {
|
|
177
|
+
index: number;
|
|
178
|
+
diffFile: DiffFile;
|
|
179
|
+
lineNumber: number;
|
|
180
|
+
enableWrap: boolean;
|
|
181
|
+
enableHighlight: boolean;
|
|
182
|
+
enableAddWidget: boolean;
|
|
183
|
+
}) => {
|
|
184
|
+
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
187
185
|
|
|
188
|
-
|
|
186
|
+
const { useDiffContext } = useDiffViewContext();
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
191
189
|
|
|
192
|
-
|
|
190
|
+
const { useWidget } = useDiffWidgetContext();
|
|
193
191
|
|
|
194
|
-
|
|
192
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
195
193
|
|
|
196
|
-
|
|
194
|
+
const hasDiff = unifiedLine.diff;
|
|
197
195
|
|
|
198
|
-
|
|
196
|
+
const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
|
|
199
197
|
|
|
200
|
-
|
|
198
|
+
const rawLine = unifiedLine.value || "";
|
|
201
199
|
|
|
202
|
-
|
|
200
|
+
const diffLine = unifiedLine.diff;
|
|
203
201
|
|
|
204
|
-
|
|
202
|
+
const newLineNumber = unifiedLine.newLineNumber;
|
|
205
203
|
|
|
206
|
-
|
|
204
|
+
const oldLinenumber = unifiedLine.oldLineNumber;
|
|
207
205
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
206
|
+
const syntaxLine = newLineNumber
|
|
207
|
+
? diffFile.getNewSyntaxLine(newLineNumber)
|
|
208
|
+
: oldLinenumber
|
|
209
|
+
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
210
|
+
: undefined;
|
|
213
211
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
212
|
+
const plainLine = newLineNumber
|
|
213
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
214
|
+
: oldLinenumber
|
|
215
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
216
|
+
: undefined;
|
|
219
217
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
if (hasChange) {
|
|
219
|
+
if (unifiedLine.oldLineNumber) {
|
|
220
|
+
return (
|
|
221
|
+
<DiffUnifiedOldLine
|
|
222
|
+
index={lineNumber}
|
|
223
|
+
enableWrap={enableWrap}
|
|
224
|
+
diffFile={diffFile}
|
|
225
|
+
rawLine={rawLine}
|
|
226
|
+
diffLine={diffLine}
|
|
227
|
+
setWidget={setWidget}
|
|
228
|
+
plainLine={plainLine}
|
|
229
|
+
syntaxLine={syntaxLine}
|
|
230
|
+
enableHighlight={enableHighlight}
|
|
231
|
+
enableAddWidget={enableAddWidget}
|
|
232
|
+
lineNumber={unifiedLine.oldLineNumber}
|
|
233
|
+
onAddWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
} else {
|
|
237
|
+
return (
|
|
238
|
+
<DiffUnifiedNewLine
|
|
239
|
+
index={lineNumber}
|
|
240
|
+
enableWrap={enableWrap}
|
|
241
|
+
rawLine={rawLine}
|
|
242
|
+
diffLine={diffLine}
|
|
243
|
+
diffFile={diffFile}
|
|
244
|
+
setWidget={setWidget}
|
|
245
|
+
plainLine={plainLine}
|
|
246
|
+
syntaxLine={syntaxLine}
|
|
247
|
+
enableHighlight={enableHighlight}
|
|
248
|
+
enableAddWidget={enableAddWidget}
|
|
249
|
+
lineNumber={unifiedLine.newLineNumber!}
|
|
250
|
+
onAddWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
return (
|
|
256
|
+
<tr data-line={lineNumber} data-state={unifiedLine.diff ? "diff" : "plain"} className="diff-line group">
|
|
257
|
+
<td
|
|
258
|
+
className="diff-line-num sticky left-0 z-[1] w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top"
|
|
259
|
+
style={{
|
|
260
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
261
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
262
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
263
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
264
|
+
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
265
|
+
}}
|
|
266
|
+
>
|
|
267
|
+
{enableAddWidget && hasDiff && (
|
|
268
|
+
<DiffUnifiedAddWidget
|
|
269
|
+
index={index}
|
|
270
|
+
diffFile={diffFile}
|
|
271
|
+
lineNumber={unifiedLine.newLineNumber}
|
|
272
|
+
side={SplitSide.new}
|
|
273
|
+
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
274
|
+
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber, side })}
|
|
275
|
+
/>
|
|
276
|
+
)}
|
|
277
|
+
<div className="flex opacity-[0.5]">
|
|
278
|
+
<span data-line-old-num={unifiedLine.oldLineNumber} className="inline-block w-[50%]">
|
|
279
|
+
{unifiedLine.oldLineNumber}
|
|
280
|
+
</span>
|
|
281
|
+
<span className="w-[10px] shrink-0" />
|
|
282
|
+
<span data-line-new-num={unifiedLine.newLineNumber} className="inline-block w-[50%]">
|
|
283
|
+
{unifiedLine.newLineNumber}
|
|
284
|
+
</span>
|
|
285
|
+
</div>
|
|
286
|
+
</td>
|
|
287
|
+
<td
|
|
288
|
+
className="diff-line-content pr-[10px] align-top"
|
|
289
|
+
style={{
|
|
290
|
+
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
<DiffContent
|
|
225
294
|
enableWrap={enableWrap}
|
|
226
295
|
diffFile={diffFile}
|
|
227
|
-
rawLine={rawLine}
|
|
228
|
-
diffLine={diffLine}
|
|
229
|
-
setWidget={setWidget}
|
|
230
|
-
plainLine={plainLine}
|
|
231
|
-
syntaxLine={syntaxLine}
|
|
232
296
|
enableHighlight={enableHighlight}
|
|
233
|
-
enableAddWidget={enableAddWidget}
|
|
234
|
-
lineNumber={unifiedLine.oldLineNumber}
|
|
235
|
-
onAddWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
236
|
-
/>
|
|
237
|
-
);
|
|
238
|
-
} else {
|
|
239
|
-
return (
|
|
240
|
-
<DiffUnifiedNewLine
|
|
241
|
-
index={lineNumber}
|
|
242
|
-
enableWrap={enableWrap}
|
|
243
297
|
rawLine={rawLine}
|
|
244
298
|
diffLine={diffLine}
|
|
245
|
-
diffFile={diffFile}
|
|
246
|
-
setWidget={setWidget}
|
|
247
299
|
plainLine={plainLine}
|
|
248
300
|
syntaxLine={syntaxLine}
|
|
249
|
-
enableHighlight={enableHighlight}
|
|
250
|
-
enableAddWidget={enableAddWidget}
|
|
251
|
-
lineNumber={unifiedLine.newLineNumber!}
|
|
252
|
-
onAddWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
253
301
|
/>
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return (
|
|
258
|
-
<tr data-line={lineNumber} data-state={unifiedLine.diff ? "diff" : "plain"} className="diff-line group">
|
|
259
|
-
<td
|
|
260
|
-
className="diff-line-num sticky left-0 z-[1] w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top"
|
|
261
|
-
style={{
|
|
262
|
-
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
263
|
-
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
264
|
-
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
265
|
-
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
266
|
-
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
267
|
-
}}
|
|
268
|
-
>
|
|
269
|
-
{enableAddWidget && hasDiff && (
|
|
270
|
-
<DiffUnifiedAddWidget
|
|
271
|
-
index={index}
|
|
272
|
-
diffFile={diffFile}
|
|
273
|
-
lineNumber={unifiedLine.newLineNumber}
|
|
274
|
-
side={SplitSide.new}
|
|
275
|
-
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
276
|
-
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber, side })}
|
|
277
|
-
/>
|
|
278
|
-
)}
|
|
279
|
-
<div className="flex opacity-[0.5]">
|
|
280
|
-
<span data-line-old-num={unifiedLine.oldLineNumber} className="inline-block w-[50%]">
|
|
281
|
-
{unifiedLine.oldLineNumber}
|
|
282
|
-
</span>
|
|
283
|
-
<span className="w-[10px] shrink-0" />
|
|
284
|
-
<span data-line-new-num={unifiedLine.newLineNumber} className="inline-block w-[50%]">
|
|
285
|
-
{unifiedLine.newLineNumber}
|
|
286
|
-
</span>
|
|
287
|
-
</div>
|
|
288
|
-
</td>
|
|
289
|
-
<td
|
|
290
|
-
className="diff-line-content pr-[10px] align-top"
|
|
291
|
-
style={{
|
|
292
|
-
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
293
|
-
}}
|
|
294
|
-
>
|
|
295
|
-
<DiffContent
|
|
296
|
-
enableWrap={enableWrap}
|
|
297
|
-
diffFile={diffFile}
|
|
298
|
-
enableHighlight={enableHighlight}
|
|
299
|
-
rawLine={rawLine}
|
|
300
|
-
diffLine={diffLine}
|
|
301
|
-
plainLine={plainLine}
|
|
302
|
-
syntaxLine={syntaxLine}
|
|
303
|
-
/>
|
|
304
|
-
</td>
|
|
305
|
-
</tr>
|
|
306
|
-
);
|
|
307
|
-
}
|
|
302
|
+
</td>
|
|
303
|
+
</tr>
|
|
304
|
+
);
|
|
308
305
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
306
|
+
};
|
|
312
307
|
|
|
313
308
|
export const DiffUnifiedContentLine = ({
|
|
314
309
|
index,
|
|
@@ -330,7 +325,7 @@ export const DiffUnifiedContentLine = ({
|
|
|
330
325
|
if (unifiedLine?.isHidden) return null;
|
|
331
326
|
|
|
332
327
|
return (
|
|
333
|
-
<
|
|
328
|
+
<InternalDiffUnifiedLine
|
|
334
329
|
index={index}
|
|
335
330
|
diffFile={diffFile}
|
|
336
331
|
lineNumber={lineNumber}
|