@git-diff-view/react 0.0.26 → 0.0.28
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 +431 -290
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +431 -290
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +4 -0
- package/dist/css/diff-view.css +4 -0
- package/dist/esm/index.mjs +362 -224
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +303 -23
- package/package.json +4 -3
- package/src/_base.css +3 -0
- package/src/_base_pure.css +2 -0
- package/src/_com.css +172 -0
- package/src/_theme.css +2 -0
- package/src/components/DiffAddWidget.tsx +86 -0
- package/src/components/DiffContent.tsx +367 -0
- package/src/components/DiffContent_v2.tsx +344 -0
- package/src/components/DiffExpand.tsx +25 -0
- package/src/components/DiffNoNewLine.tsx +10 -0
- package/src/components/DiffSplitContentLineNormal.tsx +164 -0
- package/src/components/DiffSplitContentLineWrap.tsx +234 -0
- package/src/components/DiffSplitExtendLineNormal.tsx +150 -0
- package/src/components/DiffSplitExtendLineWrap.tsx +133 -0
- package/src/components/DiffSplitHunkLineNormal.tsx +316 -0
- package/src/components/DiffSplitHunkLineWrap.tsx +340 -0
- package/src/components/DiffSplitView.tsx +46 -0
- package/src/components/DiffSplitViewNormal.tsx +205 -0
- package/src/components/DiffSplitViewWrap.tsx +141 -0
- package/src/components/DiffSplitWidgetLineNormal.tsx +149 -0
- package/src/components/DiffSplitWidgetLineWrap.tsx +127 -0
- package/src/components/DiffUnifiedContentLine.tsx +342 -0
- package/src/components/DiffUnifiedExtendLine.tsx +103 -0
- package/src/components/DiffUnifiedHunkLine.tsx +148 -0
- package/src/components/DiffUnifiedView.tsx +159 -0
- package/src/components/DiffUnifiedWidgetLine.tsx +104 -0
- package/src/components/DiffView.tsx +365 -0
- package/src/components/DiffViewContext.ts +11 -0
- package/src/components/DiffWidgetContext.ts +17 -0
- package/src/components/tools.ts +132 -0
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +152 -0
- package/src/components/v2/DiffSplitContentLineWrap_v2.tsx +259 -0
- package/src/components/v2/DiffSplitExtendLineNormal_v2.tsx +146 -0
- package/src/components/v2/DiffSplitExtendLineWrap_v2.tsx +123 -0
- package/src/components/v2/DiffSplitHunkLineNormal_v2.tsx +302 -0
- package/src/components/v2/DiffSplitHunkLineWrap_v2.tsx +326 -0
- package/src/components/v2/DiffSplitViewLineNormal_v2.tsx +33 -0
- package/src/components/v2/DiffSplitViewLineWrap_v2.tsx +24 -0
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +159 -0
- package/src/components/v2/DiffSplitViewWrap_v2.tsx +104 -0
- package/src/components/v2/DiffSplitView_v2.tsx +47 -0
- package/src/components/v2/DiffSplitWidgetLineNormal_v2.tsx +132 -0
- package/src/components/v2/DiffSplitWidgetLineWrap_v2.tsx +119 -0
- package/src/global.d.ts +12 -0
- package/src/hooks/useCallbackRef.ts +18 -0
- package/src/hooks/useDomWidth.ts +67 -0
- package/src/hooks/useIsMounted.ts +11 -0
- package/src/hooks/useSafeLayout.ts +5 -0
- package/src/hooks/useSyncHeight.ts +87 -0
- package/src/hooks/useTextWidth.ts +27 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/index.ts +3 -0
- package/src/tailwind.css +3 -0
- package/src/tailwind_pure.css +3 -0
- package/styles/diff-view-pure.css +4 -0
- package/styles/diff-view.css +4 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { DiffLineType, type DiffFile, checkDiffLineIncludeChange } from "@git-diff-view/core";
|
|
2
|
+
import {
|
|
3
|
+
getContentBG,
|
|
4
|
+
getLineNumberBG,
|
|
5
|
+
plainLineNumberColorName,
|
|
6
|
+
emptyBGName,
|
|
7
|
+
borderColorName,
|
|
8
|
+
expandLineNumberColorName,
|
|
9
|
+
} from "@git-diff-view/utils";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
|
|
12
|
+
import { SplitSide } from "..";
|
|
13
|
+
|
|
14
|
+
import { DiffSplitAddWidget } from "./DiffAddWidget";
|
|
15
|
+
import { DiffContent } from "./DiffContent";
|
|
16
|
+
// import { DiffContent_v2 } from "./DiffContent_v2";
|
|
17
|
+
import { useDiffViewContext } from "./DiffViewContext";
|
|
18
|
+
import { useDiffWidgetContext } from "./DiffWidgetContext";
|
|
19
|
+
|
|
20
|
+
const InternalDiffSplitLine = ({
|
|
21
|
+
index,
|
|
22
|
+
diffFile,
|
|
23
|
+
lineNumber,
|
|
24
|
+
enableAddWidget,
|
|
25
|
+
enableHighlight,
|
|
26
|
+
}: {
|
|
27
|
+
index: number;
|
|
28
|
+
diffFile: DiffFile;
|
|
29
|
+
lineNumber: number;
|
|
30
|
+
enableHighlight: boolean;
|
|
31
|
+
enableAddWidget: boolean;
|
|
32
|
+
}) => {
|
|
33
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
34
|
+
|
|
35
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
36
|
+
|
|
37
|
+
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine?.lineNumber);
|
|
38
|
+
|
|
39
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
40
|
+
|
|
41
|
+
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine?.lineNumber);
|
|
42
|
+
|
|
43
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
44
|
+
|
|
45
|
+
const hasDiff = !!oldLine?.diff || !!newLine?.diff;
|
|
46
|
+
|
|
47
|
+
const hasChange = checkDiffLineIncludeChange(oldLine?.diff) || checkDiffLineIncludeChange(newLine?.diff);
|
|
48
|
+
|
|
49
|
+
const oldLineIsDelete = oldLine?.diff?.type === DiffLineType.Delete;
|
|
50
|
+
|
|
51
|
+
const newLineIsAdded = newLine?.diff?.type === DiffLineType.Add;
|
|
52
|
+
|
|
53
|
+
const { useDiffContext } = useDiffViewContext();
|
|
54
|
+
|
|
55
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
56
|
+
|
|
57
|
+
const { useWidget } = useDiffWidgetContext();
|
|
58
|
+
|
|
59
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
60
|
+
|
|
61
|
+
const hasOldLine = !!oldLine.lineNumber;
|
|
62
|
+
|
|
63
|
+
const hasNewLine = !!newLine.lineNumber;
|
|
64
|
+
|
|
65
|
+
const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
|
|
66
|
+
|
|
67
|
+
const oldLineNumberBG = getLineNumberBG(false, oldLineIsDelete, hasDiff);
|
|
68
|
+
|
|
69
|
+
const newLineContentBG = getContentBG(newLineIsAdded, false, hasDiff);
|
|
70
|
+
|
|
71
|
+
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<tr data-line={lineNumber} data-state={hasDiff ? "diff" : "plain"} className="diff-line">
|
|
75
|
+
{hasOldLine ? (
|
|
76
|
+
<>
|
|
77
|
+
<td
|
|
78
|
+
className="diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top"
|
|
79
|
+
data-side={SplitSide[SplitSide.old]}
|
|
80
|
+
style={{ backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` }}
|
|
81
|
+
>
|
|
82
|
+
{hasDiff && enableAddWidget && (
|
|
83
|
+
<DiffSplitAddWidget
|
|
84
|
+
index={index}
|
|
85
|
+
lineNumber={oldLine.lineNumber}
|
|
86
|
+
side={SplitSide.old}
|
|
87
|
+
diffFile={diffFile}
|
|
88
|
+
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
89
|
+
className="absolute left-[100%] z-[1] translate-x-[-50%]"
|
|
90
|
+
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side })}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
<span data-line-num={oldLine.lineNumber} style={{ opacity: hasChange ? undefined : 0.5 }}>
|
|
94
|
+
{oldLine.lineNumber}
|
|
95
|
+
</span>
|
|
96
|
+
</td>
|
|
97
|
+
<td
|
|
98
|
+
className="diff-line-old-content group relative pr-[10px] align-top"
|
|
99
|
+
data-side={SplitSide[SplitSide.old]}
|
|
100
|
+
style={{ backgroundColor: oldLineContentBG }}
|
|
101
|
+
>
|
|
102
|
+
{hasDiff && enableAddWidget && (
|
|
103
|
+
<DiffSplitAddWidget
|
|
104
|
+
index={index}
|
|
105
|
+
lineNumber={oldLine.lineNumber}
|
|
106
|
+
side={SplitSide.old}
|
|
107
|
+
diffFile={diffFile}
|
|
108
|
+
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
109
|
+
className="absolute right-[100%] z-[1] translate-x-[50%]"
|
|
110
|
+
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side })}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
<DiffContent
|
|
114
|
+
enableWrap={true}
|
|
115
|
+
diffFile={diffFile}
|
|
116
|
+
rawLine={oldLine.value}
|
|
117
|
+
diffLine={oldLine.diff}
|
|
118
|
+
plainLine={oldPlainLine}
|
|
119
|
+
syntaxLine={oldSyntaxLine}
|
|
120
|
+
enableHighlight={enableHighlight}
|
|
121
|
+
/>
|
|
122
|
+
</td>
|
|
123
|
+
</>
|
|
124
|
+
) : (
|
|
125
|
+
<td
|
|
126
|
+
className="diff-line-old-placeholder select-none"
|
|
127
|
+
data-side={SplitSide[SplitSide.old]}
|
|
128
|
+
style={{ backgroundColor: `var(${emptyBGName})` }}
|
|
129
|
+
colSpan={2}
|
|
130
|
+
>
|
|
131
|
+
<span> </span>
|
|
132
|
+
</td>
|
|
133
|
+
)}
|
|
134
|
+
{hasNewLine ? (
|
|
135
|
+
<>
|
|
136
|
+
<td
|
|
137
|
+
className="diff-line-new-num group relative w-[1%] min-w-[40px] select-none border-l-[1px] pl-[10px] pr-[10px] text-right align-top"
|
|
138
|
+
data-side={SplitSide[SplitSide.new]}
|
|
139
|
+
style={{
|
|
140
|
+
backgroundColor: newLineNumberBG,
|
|
141
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
142
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
143
|
+
borderLeftStyle: "solid",
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
{hasDiff && enableAddWidget && (
|
|
147
|
+
<DiffSplitAddWidget
|
|
148
|
+
index={index}
|
|
149
|
+
lineNumber={newLine.lineNumber}
|
|
150
|
+
side={SplitSide.new}
|
|
151
|
+
diffFile={diffFile}
|
|
152
|
+
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
153
|
+
className="absolute left-[100%] z-[1] translate-x-[-50%]"
|
|
154
|
+
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side })}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
<span data-line-num={newLine.lineNumber} style={{ opacity: hasChange ? undefined : 0.5 }}>
|
|
158
|
+
{newLine.lineNumber}
|
|
159
|
+
</span>
|
|
160
|
+
</td>
|
|
161
|
+
<td
|
|
162
|
+
className="diff-line-new-content group relative pr-[10px] align-top"
|
|
163
|
+
data-side={SplitSide[SplitSide.new]}
|
|
164
|
+
style={{ backgroundColor: newLineContentBG }}
|
|
165
|
+
>
|
|
166
|
+
{hasDiff && enableAddWidget && (
|
|
167
|
+
<DiffSplitAddWidget
|
|
168
|
+
index={index}
|
|
169
|
+
lineNumber={newLine.lineNumber}
|
|
170
|
+
side={SplitSide.new}
|
|
171
|
+
diffFile={diffFile}
|
|
172
|
+
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
173
|
+
className="absolute right-[100%] z-[1] translate-x-[50%]"
|
|
174
|
+
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side })}
|
|
175
|
+
/>
|
|
176
|
+
)}
|
|
177
|
+
<DiffContent
|
|
178
|
+
enableWrap={true}
|
|
179
|
+
diffFile={diffFile}
|
|
180
|
+
rawLine={newLine.value || ""}
|
|
181
|
+
diffLine={newLine.diff}
|
|
182
|
+
plainLine={newPlainLine}
|
|
183
|
+
syntaxLine={newSyntaxLine}
|
|
184
|
+
enableHighlight={enableHighlight}
|
|
185
|
+
/>
|
|
186
|
+
</td>
|
|
187
|
+
</>
|
|
188
|
+
) : (
|
|
189
|
+
<td
|
|
190
|
+
className="diff-line-new-placeholder select-none border-l-[1px]"
|
|
191
|
+
style={{
|
|
192
|
+
backgroundColor: `var(${emptyBGName})`,
|
|
193
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
194
|
+
borderLeftStyle: "solid",
|
|
195
|
+
}}
|
|
196
|
+
data-side={SplitSide[SplitSide.new]}
|
|
197
|
+
colSpan={2}
|
|
198
|
+
>
|
|
199
|
+
<span> </span>
|
|
200
|
+
</td>
|
|
201
|
+
)}
|
|
202
|
+
</tr>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export const DiffSplitContentLine = ({
|
|
207
|
+
index,
|
|
208
|
+
diffFile,
|
|
209
|
+
lineNumber,
|
|
210
|
+
enableAddWidget,
|
|
211
|
+
enableHighlight,
|
|
212
|
+
}: {
|
|
213
|
+
index: number;
|
|
214
|
+
diffFile: DiffFile;
|
|
215
|
+
lineNumber: number;
|
|
216
|
+
enableHighlight: boolean;
|
|
217
|
+
enableAddWidget: boolean;
|
|
218
|
+
}) => {
|
|
219
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
220
|
+
|
|
221
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
222
|
+
|
|
223
|
+
if (oldLine?.isHidden && newLine?.isHidden) return null;
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<InternalDiffSplitLine
|
|
227
|
+
index={index}
|
|
228
|
+
diffFile={diffFile}
|
|
229
|
+
lineNumber={lineNumber}
|
|
230
|
+
enableAddWidget={enableAddWidget}
|
|
231
|
+
enableHighlight={enableHighlight}
|
|
232
|
+
/>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { emptyBGName } from "@git-diff-view/utils";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
import { SplitSide } from "..";
|
|
5
|
+
import { useDomWidth } from "../hooks/useDomWidth";
|
|
6
|
+
import { useSyncHeight } from "../hooks/useSyncHeight";
|
|
7
|
+
|
|
8
|
+
import { useDiffViewContext } from "./DiffViewContext";
|
|
9
|
+
|
|
10
|
+
import type { DiffFile } from "@git-diff-view/core";
|
|
11
|
+
|
|
12
|
+
const InternalDiffSplitExtendLine = ({
|
|
13
|
+
index,
|
|
14
|
+
diffFile,
|
|
15
|
+
oldLineExtend,
|
|
16
|
+
newLineExtend,
|
|
17
|
+
side,
|
|
18
|
+
lineNumber,
|
|
19
|
+
}: {
|
|
20
|
+
index: number;
|
|
21
|
+
side: SplitSide;
|
|
22
|
+
oldLineExtend: { data: any };
|
|
23
|
+
newLineExtend: { data: any };
|
|
24
|
+
diffFile: DiffFile;
|
|
25
|
+
lineNumber: number;
|
|
26
|
+
}) => {
|
|
27
|
+
const { useDiffContext } = useDiffViewContext();
|
|
28
|
+
|
|
29
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
30
|
+
|
|
31
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
32
|
+
|
|
33
|
+
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
34
|
+
|
|
35
|
+
const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
|
|
36
|
+
|
|
37
|
+
const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
38
|
+
|
|
39
|
+
const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
40
|
+
|
|
41
|
+
const currentSideHasExtend = currentExtend?.data !== undefined && currentExtend?.data !== null;
|
|
42
|
+
|
|
43
|
+
const hasExtend =
|
|
44
|
+
(oldLineExtend?.data !== undefined && oldLineExtend?.data !== null) ||
|
|
45
|
+
(newLineExtend?.data !== undefined && newLineExtend?.data !== null);
|
|
46
|
+
|
|
47
|
+
const currentExtendRendered =
|
|
48
|
+
hasExtend &&
|
|
49
|
+
renderExtendLine?.({
|
|
50
|
+
diffFile,
|
|
51
|
+
side,
|
|
52
|
+
lineNumber: currentLineNumber,
|
|
53
|
+
data: currentExtend?.data,
|
|
54
|
+
onUpdate: diffFile.notifyAll,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
useSyncHeight({
|
|
58
|
+
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
59
|
+
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
60
|
+
side: SplitSide[currentSideHasExtend ? side : otherSide],
|
|
61
|
+
enable: hasExtend && typeof renderExtendLine === "function",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const width = useDomWidth({
|
|
65
|
+
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
66
|
+
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!renderExtendLine) return null;
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<tr
|
|
73
|
+
data-line={`${lineNumber}-extend`}
|
|
74
|
+
data-state="extend"
|
|
75
|
+
data-side={SplitSide[side]}
|
|
76
|
+
className="diff-line diff-line-extend"
|
|
77
|
+
>
|
|
78
|
+
{currentSideHasExtend ? (
|
|
79
|
+
<td className={`diff-line-extend-${SplitSide[side]}-content p-0`} colSpan={2}>
|
|
80
|
+
<div
|
|
81
|
+
data-line={`${lineNumber}-extend-content`}
|
|
82
|
+
data-side={SplitSide[side]}
|
|
83
|
+
className="diff-line-extend-wrapper sticky left-0 z-[1]"
|
|
84
|
+
style={{ width }}
|
|
85
|
+
>
|
|
86
|
+
{width > 0 && currentExtendRendered}
|
|
87
|
+
</div>
|
|
88
|
+
</td>
|
|
89
|
+
) : (
|
|
90
|
+
<td
|
|
91
|
+
className={`diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`}
|
|
92
|
+
style={{ backgroundColor: `var(${emptyBGName})` }}
|
|
93
|
+
colSpan={2}
|
|
94
|
+
>
|
|
95
|
+
<div data-line={`${lineNumber}-extend-content`} data-side={SplitSide[side]} />
|
|
96
|
+
</td>
|
|
97
|
+
)}
|
|
98
|
+
</tr>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const DiffSplitExtendLine = ({
|
|
103
|
+
index,
|
|
104
|
+
diffFile,
|
|
105
|
+
side,
|
|
106
|
+
lineNumber,
|
|
107
|
+
}: {
|
|
108
|
+
index: number;
|
|
109
|
+
side: SplitSide;
|
|
110
|
+
diffFile: DiffFile;
|
|
111
|
+
lineNumber: number;
|
|
112
|
+
}) => {
|
|
113
|
+
const { useDiffContext } = useDiffViewContext();
|
|
114
|
+
|
|
115
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
116
|
+
|
|
117
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
118
|
+
|
|
119
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(
|
|
120
|
+
React.useCallback(
|
|
121
|
+
(s) => ({
|
|
122
|
+
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber],
|
|
123
|
+
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber],
|
|
124
|
+
}),
|
|
125
|
+
[oldLine?.lineNumber, newLine?.lineNumber]
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const hasExtend = oldLineExtend?.data || newLineExtend?.data;
|
|
130
|
+
|
|
131
|
+
// if the expand action not enabled, the `isHidden` property will never change
|
|
132
|
+
const enableExpand = diffFile.getExpandEnabled();
|
|
133
|
+
|
|
134
|
+
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
135
|
+
|
|
136
|
+
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
137
|
+
|
|
138
|
+
if (!currentIsShow) return null;
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<InternalDiffSplitExtendLine
|
|
142
|
+
side={side}
|
|
143
|
+
index={index}
|
|
144
|
+
diffFile={diffFile}
|
|
145
|
+
lineNumber={lineNumber}
|
|
146
|
+
oldLineExtend={oldLineExtend}
|
|
147
|
+
newLineExtend={newLineExtend}
|
|
148
|
+
/>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { emptyBGName, borderColorName } from "@git-diff-view/utils";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
import { SplitSide } from "..";
|
|
5
|
+
|
|
6
|
+
import { useDiffViewContext } from "./DiffViewContext";
|
|
7
|
+
|
|
8
|
+
import type { DiffFile } from "@git-diff-view/core";
|
|
9
|
+
|
|
10
|
+
const InternalDiffSplitExtendLine = ({
|
|
11
|
+
index,
|
|
12
|
+
diffFile,
|
|
13
|
+
lineNumber,
|
|
14
|
+
oldLineExtend,
|
|
15
|
+
newLineExtend,
|
|
16
|
+
}: {
|
|
17
|
+
index: number;
|
|
18
|
+
diffFile: DiffFile;
|
|
19
|
+
lineNumber: number;
|
|
20
|
+
oldLineExtend: { data: any };
|
|
21
|
+
newLineExtend: { data: any };
|
|
22
|
+
}) => {
|
|
23
|
+
const { useDiffContext } = useDiffViewContext();
|
|
24
|
+
|
|
25
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
26
|
+
|
|
27
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
28
|
+
|
|
29
|
+
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
30
|
+
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
31
|
+
|
|
32
|
+
if (!renderExtendLine) return null;
|
|
33
|
+
|
|
34
|
+
const oldExtendRendered =
|
|
35
|
+
oldLineExtend?.data &&
|
|
36
|
+
renderExtendLine?.({
|
|
37
|
+
diffFile,
|
|
38
|
+
side: SplitSide.old,
|
|
39
|
+
lineNumber: oldLine.lineNumber,
|
|
40
|
+
data: oldLineExtend.data,
|
|
41
|
+
onUpdate: diffFile.notifyAll,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const newExtendRendered =
|
|
45
|
+
newLineExtend?.data &&
|
|
46
|
+
renderExtendLine?.({
|
|
47
|
+
diffFile,
|
|
48
|
+
side: SplitSide.new,
|
|
49
|
+
lineNumber: newLine.lineNumber,
|
|
50
|
+
data: newLineExtend.data,
|
|
51
|
+
onUpdate: diffFile.notifyAll,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<tr data-line={`${lineNumber}-extend`} data-state="extend" className="diff-line diff-line-extend">
|
|
56
|
+
{oldExtendRendered ? (
|
|
57
|
+
<td className="diff-line-extend-old-content p-0" colSpan={2}>
|
|
58
|
+
<div className="diff-line-extend-wrapper">{oldExtendRendered}</div>
|
|
59
|
+
</td>
|
|
60
|
+
) : (
|
|
61
|
+
<td
|
|
62
|
+
className="diff-line-extend-old-placeholder select-none p-0"
|
|
63
|
+
style={{ backgroundColor: `var(${emptyBGName})` }}
|
|
64
|
+
colSpan={2}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
{newExtendRendered ? (
|
|
68
|
+
<td
|
|
69
|
+
className="diff-line-extend-new-content border-l-[1px] p-0"
|
|
70
|
+
style={{ borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }}
|
|
71
|
+
colSpan={2}
|
|
72
|
+
>
|
|
73
|
+
<div className="diff-line-extend-wrapper">{newExtendRendered}</div>
|
|
74
|
+
</td>
|
|
75
|
+
) : (
|
|
76
|
+
<td
|
|
77
|
+
className="diff-line-extend-new-placeholder select-none border-l-[1px] p-0"
|
|
78
|
+
style={{
|
|
79
|
+
backgroundColor: `var(${emptyBGName})`,
|
|
80
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
81
|
+
borderLeftStyle: "solid",
|
|
82
|
+
}}
|
|
83
|
+
colSpan={2}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</tr>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const DiffSplitExtendLine = ({
|
|
91
|
+
index,
|
|
92
|
+
diffFile,
|
|
93
|
+
lineNumber,
|
|
94
|
+
}: {
|
|
95
|
+
index: number;
|
|
96
|
+
diffFile: DiffFile;
|
|
97
|
+
lineNumber: number;
|
|
98
|
+
}) => {
|
|
99
|
+
const { useDiffContext } = useDiffViewContext();
|
|
100
|
+
|
|
101
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
102
|
+
|
|
103
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
104
|
+
|
|
105
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(
|
|
106
|
+
React.useCallback(
|
|
107
|
+
(s) => ({
|
|
108
|
+
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber],
|
|
109
|
+
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber],
|
|
110
|
+
}),
|
|
111
|
+
[oldLine?.lineNumber, newLine?.lineNumber]
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const hasExtend = oldLineExtend?.data || newLineExtend?.data;
|
|
116
|
+
|
|
117
|
+
// if the expand action not enabled, the `isHidden` property will never change
|
|
118
|
+
const enableExpand = diffFile.getExpandEnabled();
|
|
119
|
+
|
|
120
|
+
const currentIsShow = hasExtend && ((!oldLine?.isHidden && !newLine?.isHidden) || !enableExpand);
|
|
121
|
+
|
|
122
|
+
if (!currentIsShow) return null;
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<InternalDiffSplitExtendLine
|
|
126
|
+
index={index}
|
|
127
|
+
diffFile={diffFile}
|
|
128
|
+
lineNumber={lineNumber}
|
|
129
|
+
oldLineExtend={oldLineExtend}
|
|
130
|
+
newLineExtend={newLineExtend}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
};
|