@git-diff-view/react 0.1.3 → 0.1.5
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 +497 -503
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +497 -503
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +111 -0
- package/dist/css/diff-view.css +111 -0
- package/dist/esm/index.mjs +499 -506
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +239 -7
- package/package.json +2 -2
- package/src/_com.css +99 -0
- package/src/components/DiffAddWidget.tsx +4 -3
- package/src/components/DiffContent.tsx +6 -6
- package/src/components/DiffExpand.tsx +0 -2
- package/src/components/DiffNoNewLine.tsx +0 -2
- package/src/components/DiffSplitContentLineNormal.tsx +3 -4
- package/src/components/DiffSplitContentLineWrap.tsx +9 -10
- package/src/components/DiffSplitExtendLineNormal.tsx +3 -3
- package/src/components/DiffSplitExtendLineWrap.tsx +4 -4
- package/src/components/DiffSplitHunkLineNormal.tsx +0 -1
- package/src/components/DiffSplitHunkLineWrap.tsx +0 -1
- package/src/components/DiffSplitView.tsx +0 -1
- package/src/components/DiffSplitViewNormal.tsx +13 -12
- package/src/components/DiffSplitViewWrap.tsx +10 -10
- package/src/components/DiffSplitWidgetLineNormal.tsx +2 -2
- package/src/components/DiffSplitWidgetLineWrap.tsx +12 -2
- package/src/components/DiffUnifiedContentLine.tsx +1 -2
- package/src/components/DiffUnifiedExtendLine.tsx +4 -5
- package/src/components/DiffUnifiedHunkLine.tsx +0 -1
- package/src/components/DiffUnifiedView.tsx +9 -9
- package/src/components/DiffUnifiedWidgetLine.tsx +2 -2
- package/src/components/DiffView.tsx +26 -20
- package/src/components/DiffViewContext.ts +2 -0
- package/src/components/DiffViewWithMultiSelect.tsx +321 -0
- package/src/components/DiffWidgetContext.ts +4 -2
- package/src/components/tools.ts +6 -5
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +4 -5
- package/src/components/v2/DiffSplitContentLineWrap_v2.tsx +11 -12
- package/src/components/v2/DiffSplitExtendLineNormal_v2.tsx +3 -3
- package/src/components/v2/DiffSplitExtendLineWrap_v2.tsx +4 -4
- package/src/components/v2/DiffSplitHunkLineNormal_v2.tsx +0 -1
- package/src/components/v2/DiffSplitHunkLineWrap_v2.tsx +0 -1
- package/src/components/v2/DiffSplitViewLineNormal_v2.tsx +0 -1
- package/src/components/v2/DiffSplitViewLineWrap_v2.tsx +0 -1
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +9 -8
- package/src/components/v2/DiffSplitViewWrap_v2.tsx +5 -5
- package/src/components/v2/DiffSplitView_v2.tsx +0 -1
- package/src/components/v2/DiffSplitWidgetLineNormal_v2.tsx +2 -3
- package/src/components/v2/DiffSplitWidgetLineWrap_v2.tsx +4 -5
- package/src/hooks/useCallbackRef.ts +13 -0
- package/src/hooks/useDomWidth.ts +5 -5
- package/src/hooks/useIsMounted.ts +1 -0
- package/src/hooks/useSyncHeight.ts +3 -3
- package/src/hooks/useTextWidth.ts +1 -1
- package/src/hooks/useUnmount.ts +1 -0
- package/src/hooks/useUpdateEffect.ts +15 -0
- package/src/index.ts +1 -2
- package/styles/diff-view-pure.css +111 -0
- package/styles/diff-view.css +111 -0
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
borderColorName,
|
|
8
8
|
expandLineNumberColorName,
|
|
9
9
|
} from "@git-diff-view/utils";
|
|
10
|
-
import * as React from "react";
|
|
11
10
|
|
|
12
11
|
import { SplitSide } from "..";
|
|
13
12
|
|
|
@@ -33,13 +32,13 @@ const InternalDiffSplitLine = ({
|
|
|
33
32
|
|
|
34
33
|
const newLine = diffFile.getSplitRightLine(index);
|
|
35
34
|
|
|
36
|
-
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine?.lineNumber);
|
|
35
|
+
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine?.lineNumber ?? -1);
|
|
37
36
|
|
|
38
|
-
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
37
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber ?? -1);
|
|
39
38
|
|
|
40
|
-
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine?.lineNumber);
|
|
39
|
+
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine?.lineNumber ?? -1);
|
|
41
40
|
|
|
42
|
-
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
41
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber ?? -1);
|
|
43
42
|
|
|
44
43
|
const hasDiff = !!oldLine?.diff || !!newLine?.diff;
|
|
45
44
|
|
|
@@ -84,7 +83,7 @@ const InternalDiffSplitLine = ({
|
|
|
84
83
|
{hasDiff && enableAddWidget && (
|
|
85
84
|
<DiffSplitAddWidget
|
|
86
85
|
index={index}
|
|
87
|
-
lineNumber={oldLine.lineNumber}
|
|
86
|
+
lineNumber={oldLine.lineNumber ?? -1}
|
|
88
87
|
side={SplitSide.old}
|
|
89
88
|
diffFile={diffFile}
|
|
90
89
|
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
@@ -104,7 +103,7 @@ const InternalDiffSplitLine = ({
|
|
|
104
103
|
{hasDiff && enableAddWidget && (
|
|
105
104
|
<DiffSplitAddWidget
|
|
106
105
|
index={index}
|
|
107
|
-
lineNumber={oldLine.lineNumber}
|
|
106
|
+
lineNumber={oldLine.lineNumber ?? -1}
|
|
108
107
|
side={SplitSide.old}
|
|
109
108
|
diffFile={diffFile}
|
|
110
109
|
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
@@ -115,7 +114,7 @@ const InternalDiffSplitLine = ({
|
|
|
115
114
|
<DiffContent
|
|
116
115
|
enableWrap={true}
|
|
117
116
|
diffFile={diffFile}
|
|
118
|
-
rawLine={oldLine.value}
|
|
117
|
+
rawLine={oldLine.value || ""}
|
|
119
118
|
diffLine={oldLine.diff}
|
|
120
119
|
plainLine={oldPlainLine}
|
|
121
120
|
syntaxLine={oldSyntaxLine}
|
|
@@ -148,7 +147,7 @@ const InternalDiffSplitLine = ({
|
|
|
148
147
|
{hasDiff && enableAddWidget && (
|
|
149
148
|
<DiffSplitAddWidget
|
|
150
149
|
index={index}
|
|
151
|
-
lineNumber={newLine.lineNumber}
|
|
150
|
+
lineNumber={newLine.lineNumber ?? -1}
|
|
152
151
|
side={SplitSide.new}
|
|
153
152
|
diffFile={diffFile}
|
|
154
153
|
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
@@ -168,7 +167,7 @@ const InternalDiffSplitLine = ({
|
|
|
168
167
|
{hasDiff && enableAddWidget && (
|
|
169
168
|
<DiffSplitAddWidget
|
|
170
169
|
index={index}
|
|
171
|
-
lineNumber={newLine.lineNumber}
|
|
170
|
+
lineNumber={newLine.lineNumber ?? -1}
|
|
172
171
|
side={SplitSide.new}
|
|
173
172
|
diffFile={diffFile}
|
|
174
173
|
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
@@ -49,7 +49,7 @@ const InternalDiffSplitExtendLine = ({
|
|
|
49
49
|
renderExtendLine?.({
|
|
50
50
|
diffFile,
|
|
51
51
|
side,
|
|
52
|
-
lineNumber: currentLineNumber,
|
|
52
|
+
lineNumber: currentLineNumber ?? -1,
|
|
53
53
|
data: currentExtend?.data,
|
|
54
54
|
onUpdate: diffFile.notifyAll,
|
|
55
55
|
});
|
|
@@ -119,8 +119,8 @@ export const DiffSplitExtendLine = ({
|
|
|
119
119
|
const { oldLineExtend, newLineExtend } = useDiffContext(
|
|
120
120
|
React.useCallback(
|
|
121
121
|
(s) => ({
|
|
122
|
-
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber],
|
|
123
|
-
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber],
|
|
122
|
+
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber ?? -1],
|
|
123
|
+
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber ?? -1],
|
|
124
124
|
}),
|
|
125
125
|
[oldLine?.lineNumber, newLine?.lineNumber]
|
|
126
126
|
)
|
|
@@ -36,7 +36,7 @@ const InternalDiffSplitExtendLine = ({
|
|
|
36
36
|
renderExtendLine?.({
|
|
37
37
|
diffFile,
|
|
38
38
|
side: SplitSide.old,
|
|
39
|
-
lineNumber: oldLine.lineNumber,
|
|
39
|
+
lineNumber: oldLine.lineNumber ?? -1,
|
|
40
40
|
data: oldLineExtend.data,
|
|
41
41
|
onUpdate: diffFile.notifyAll,
|
|
42
42
|
});
|
|
@@ -46,7 +46,7 @@ const InternalDiffSplitExtendLine = ({
|
|
|
46
46
|
renderExtendLine?.({
|
|
47
47
|
diffFile,
|
|
48
48
|
side: SplitSide.new,
|
|
49
|
-
lineNumber: newLine.lineNumber,
|
|
49
|
+
lineNumber: newLine.lineNumber ?? -1,
|
|
50
50
|
data: newLineExtend.data,
|
|
51
51
|
onUpdate: diffFile.notifyAll,
|
|
52
52
|
});
|
|
@@ -105,8 +105,8 @@ export const DiffSplitExtendLine = ({
|
|
|
105
105
|
const { oldLineExtend, newLineExtend } = useDiffContext(
|
|
106
106
|
React.useCallback(
|
|
107
107
|
(s) => ({
|
|
108
|
-
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber],
|
|
109
|
-
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber],
|
|
108
|
+
oldLineExtend: s.extendData?.oldFile?.[oldLine?.lineNumber ?? -1],
|
|
109
|
+
newLineExtend: s.extendData?.newFile?.[newLine?.lineNumber ?? -1],
|
|
110
110
|
}),
|
|
111
111
|
[oldLine?.lineNumber, newLine?.lineNumber]
|
|
112
112
|
)
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "@git-diff-view/utils";
|
|
11
11
|
import { Fragment, memo, useEffect, useRef } from "react";
|
|
12
12
|
import * as React from "react";
|
|
13
|
+
// @ts-ignore
|
|
13
14
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
14
15
|
|
|
15
16
|
import { useTextWidth } from "../hooks/useTextWidth";
|
|
@@ -84,9 +85,9 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
84
85
|
|
|
85
86
|
const ref2 = useRef<HTMLDivElement>(null);
|
|
86
87
|
|
|
87
|
-
const ref = useRef<HTMLStyleElement>();
|
|
88
|
+
const ref = useRef<HTMLStyleElement>(null);
|
|
88
89
|
|
|
89
|
-
const tempRef = useRef<SplitSide>();
|
|
90
|
+
const tempRef = useRef<SplitSide>(undefined);
|
|
90
91
|
|
|
91
92
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
92
93
|
|
|
@@ -119,7 +120,7 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
119
120
|
|
|
120
121
|
const width = Math.max(40, _width + 25);
|
|
121
122
|
|
|
122
|
-
const setStyle = (side
|
|
123
|
+
const setStyle = (side?: SplitSide) => {
|
|
123
124
|
if (!ref.current) return;
|
|
124
125
|
if (!side) {
|
|
125
126
|
ref.current.textContent = "";
|
|
@@ -130,7 +131,7 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
const onMouseDown: MouseEventHandler<HTMLTableSectionElement> = (e) => {
|
|
133
|
-
let ele = e.target;
|
|
134
|
+
let ele: Element | null = e.target as Element;
|
|
134
135
|
|
|
135
136
|
// need remove all the selection
|
|
136
137
|
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
@@ -146,11 +147,11 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
146
147
|
|
|
147
148
|
while (ele && ele instanceof HTMLElement) {
|
|
148
149
|
const state = ele.getAttribute("data-state");
|
|
149
|
-
const side = ele.getAttribute("data-side");
|
|
150
|
+
const side = ele.getAttribute("data-side") as unknown as SplitSide;
|
|
150
151
|
if (side) {
|
|
151
|
-
if (tempRef.current !== SplitSide[side]) {
|
|
152
|
-
tempRef.current = SplitSide[side];
|
|
153
|
-
setStyle(SplitSide[side]);
|
|
152
|
+
if (tempRef.current !== (SplitSide[side] as unknown as SplitSide)) {
|
|
153
|
+
tempRef.current = SplitSide[side] as unknown as SplitSide;
|
|
154
|
+
setStyle(SplitSide[side] as unknown as SplitSide);
|
|
154
155
|
removeAllSelection();
|
|
155
156
|
}
|
|
156
157
|
}
|
|
@@ -188,8 +189,8 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
188
189
|
<DiffSplitViewTable
|
|
189
190
|
side={SplitSide.old}
|
|
190
191
|
diffFile={diffFile}
|
|
191
|
-
enableAddWidget={enableAddWidget}
|
|
192
|
-
enableHighlight={enableHighlight}
|
|
192
|
+
enableAddWidget={!!enableAddWidget}
|
|
193
|
+
enableHighlight={!!enableHighlight}
|
|
193
194
|
onMouseDown={onMouseDown}
|
|
194
195
|
/>
|
|
195
196
|
</div>
|
|
@@ -208,8 +209,8 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
208
209
|
<DiffSplitViewTable
|
|
209
210
|
side={SplitSide.new}
|
|
210
211
|
diffFile={diffFile}
|
|
211
|
-
enableAddWidget={enableAddWidget}
|
|
212
|
-
enableHighlight={enableHighlight}
|
|
212
|
+
enableAddWidget={!!enableAddWidget}
|
|
213
|
+
enableHighlight={!!enableHighlight}
|
|
213
214
|
onMouseDown={onMouseDown}
|
|
214
215
|
/>
|
|
215
216
|
</div>
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { type DiffFile, getSplitContentLines } from "@git-diff-view/core";
|
|
3
3
|
import { diffAsideWidthName, diffFontSizeName, getDiffIdFromElement, removeAllSelection } from "@git-diff-view/utils";
|
|
4
4
|
import { Fragment, memo, useMemo, useRef } from "react";
|
|
5
|
-
import * as React from "react";
|
|
6
5
|
// SEE https://github.com/facebook/react/pull/25231
|
|
6
|
+
// @ts-ignore
|
|
7
7
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
8
8
|
|
|
9
9
|
import { SplitSide } from "..";
|
|
@@ -24,7 +24,7 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
24
24
|
|
|
25
25
|
const ref = useRef<HTMLStyleElement>(null);
|
|
26
26
|
|
|
27
|
-
const tempRef = useRef<SplitSide>();
|
|
27
|
+
const tempRef = useRef<SplitSide>(undefined);
|
|
28
28
|
|
|
29
29
|
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
30
30
|
fontSize: s.fontSize,
|
|
@@ -45,7 +45,7 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
45
45
|
|
|
46
46
|
const lines = getSplitContentLines(diffFile);
|
|
47
47
|
|
|
48
|
-
const setStyle = (side
|
|
48
|
+
const setStyle = (side?: SplitSide) => {
|
|
49
49
|
if (!ref.current) return;
|
|
50
50
|
if (!side) {
|
|
51
51
|
ref.current.textContent = "";
|
|
@@ -57,7 +57,7 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
const onMouseDown: MouseEventHandler<HTMLTableSectionElement> = (e) => {
|
|
60
|
-
let ele = e.target;
|
|
60
|
+
let ele: Element | null = e.target as Element;
|
|
61
61
|
|
|
62
62
|
// need remove all the selection
|
|
63
63
|
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
@@ -73,11 +73,11 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
73
73
|
|
|
74
74
|
while (ele && ele instanceof HTMLElement) {
|
|
75
75
|
const state = ele.getAttribute("data-state");
|
|
76
|
-
const side = ele.getAttribute("data-side");
|
|
76
|
+
const side = ele.getAttribute("data-side") as unknown as SplitSide;
|
|
77
77
|
if (side) {
|
|
78
|
-
if (tempRef.current !== SplitSide[side]) {
|
|
79
|
-
tempRef.current = SplitSide[side];
|
|
80
|
-
setStyle(SplitSide[side]);
|
|
78
|
+
if (tempRef.current !== (SplitSide[side] as unknown as SplitSide)) {
|
|
79
|
+
tempRef.current = SplitSide[side] as unknown as SplitSide;
|
|
80
|
+
setStyle(SplitSide[side] as unknown as SplitSide);
|
|
81
81
|
removeAllSelection();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -133,8 +133,8 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
133
133
|
index={line.index}
|
|
134
134
|
lineNumber={line.lineNumber}
|
|
135
135
|
diffFile={diffFile}
|
|
136
|
-
enableAddWidget={enableAddWidget}
|
|
137
|
-
enableHighlight={enableHighlight}
|
|
136
|
+
enableAddWidget={!!enableAddWidget}
|
|
137
|
+
enableHighlight={!!enableHighlight}
|
|
138
138
|
/>
|
|
139
139
|
<DiffSplitWidgetLine index={line.index} lineNumber={line.lineNumber} diffFile={diffFile} />
|
|
140
140
|
<DiffSplitExtendLine index={line.index} lineNumber={line.lineNumber} diffFile={diffFile} />
|
|
@@ -54,7 +54,7 @@ const InternalDiffSplitWidgetLine = ({
|
|
|
54
54
|
renderWidgetLine?.({
|
|
55
55
|
diffFile,
|
|
56
56
|
side,
|
|
57
|
-
lineNumber: currentLine.lineNumber,
|
|
57
|
+
lineNumber: currentLine.lineNumber ?? -1,
|
|
58
58
|
onClose: () => setWidget({}),
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ const InternalDiffSplitWidgetLine = ({
|
|
|
62
62
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
63
63
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
64
64
|
side: SplitSide[currentHasWidget ? side : otherSide],
|
|
65
|
-
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
65
|
+
enable: !!hasWidget && typeof renderWidgetLine === "function",
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
const width = useDomWidth({
|
|
@@ -39,11 +39,21 @@ const InternalDiffSplitWidgetLine = ({
|
|
|
39
39
|
|
|
40
40
|
const oldWidgetRendered =
|
|
41
41
|
oldLineWidget &&
|
|
42
|
-
renderWidgetLine?.({
|
|
42
|
+
renderWidgetLine?.({
|
|
43
|
+
diffFile,
|
|
44
|
+
side: SplitSide.old,
|
|
45
|
+
lineNumber: oldLine.lineNumber ?? -1,
|
|
46
|
+
onClose: () => setWidget({}),
|
|
47
|
+
});
|
|
43
48
|
|
|
44
49
|
const newWidgetRendered =
|
|
45
50
|
newLineWidget &&
|
|
46
|
-
renderWidgetLine?.({
|
|
51
|
+
renderWidgetLine?.({
|
|
52
|
+
diffFile,
|
|
53
|
+
side: SplitSide.new,
|
|
54
|
+
lineNumber: newLine.lineNumber ?? -1,
|
|
55
|
+
onClose: () => setWidget({}),
|
|
56
|
+
});
|
|
47
57
|
|
|
48
58
|
if (!renderWidgetLine) return null;
|
|
49
59
|
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
plainLineNumberColorName,
|
|
12
12
|
expandLineNumberColorName,
|
|
13
13
|
} from "@git-diff-view/utils";
|
|
14
|
-
import * as React from "react";
|
|
15
14
|
|
|
16
15
|
import { SplitSide } from "..";
|
|
17
16
|
|
|
@@ -268,7 +267,7 @@ const InternalDiffUnifiedLine = ({
|
|
|
268
267
|
<DiffUnifiedAddWidget
|
|
269
268
|
index={index}
|
|
270
269
|
diffFile={diffFile}
|
|
271
|
-
lineNumber={unifiedLine.newLineNumber}
|
|
270
|
+
lineNumber={unifiedLine.newLineNumber ?? -1}
|
|
272
271
|
side={SplitSide.new}
|
|
273
272
|
onWidgetClick={(...props) => onAddWidgetClick.current?.(...props)}
|
|
274
273
|
onOpenAddWidget={(lineNumber, side) => setWidget({ lineNumber, side })}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
import { useCallback } from "react";
|
|
3
2
|
|
|
4
3
|
import { SplitSide } from "..";
|
|
@@ -47,7 +46,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
47
46
|
renderExtendLine?.({
|
|
48
47
|
diffFile,
|
|
49
48
|
side: SplitSide.old,
|
|
50
|
-
lineNumber: unifiedItem.oldLineNumber,
|
|
49
|
+
lineNumber: unifiedItem.oldLineNumber ?? -1,
|
|
51
50
|
data: oldLineExtend.data,
|
|
52
51
|
onUpdate: diffFile.notifyAll,
|
|
53
52
|
})}
|
|
@@ -57,7 +56,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
57
56
|
renderExtendLine?.({
|
|
58
57
|
diffFile,
|
|
59
58
|
side: SplitSide.new,
|
|
60
|
-
lineNumber: unifiedItem.newLineNumber,
|
|
59
|
+
lineNumber: unifiedItem.newLineNumber ?? -1,
|
|
61
60
|
data: newLineExtend.data,
|
|
62
61
|
onUpdate: diffFile.notifyAll,
|
|
63
62
|
})}
|
|
@@ -85,8 +84,8 @@ export const DiffUnifiedExtendLine = ({
|
|
|
85
84
|
const { oldLineExtend, newLineExtend } = useDiffContext(
|
|
86
85
|
useCallback(
|
|
87
86
|
(s) => ({
|
|
88
|
-
oldLineExtend: s.extendData?.oldFile?.[unifiedItem?.oldLineNumber],
|
|
89
|
-
newLineExtend: s.extendData?.newFile?.[unifiedItem?.newLineNumber],
|
|
87
|
+
oldLineExtend: s.extendData?.oldFile?.[unifiedItem?.oldLineNumber ?? -1],
|
|
88
|
+
newLineExtend: s.extendData?.newFile?.[unifiedItem?.newLineNumber ?? -1],
|
|
90
89
|
}),
|
|
91
90
|
[unifiedItem.oldLineNumber, unifiedItem.newLineNumber]
|
|
92
91
|
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
import { getUnifiedContentLine, SplitSide } from "@git-diff-view/core";
|
|
3
3
|
import { diffFontSizeName, removeAllSelection, diffAsideWidthName, getDiffIdFromElement } from "@git-diff-view/utils";
|
|
4
|
-
import * as React from "react";
|
|
5
4
|
import { Fragment, memo, useEffect, useMemo, useRef } from "react";
|
|
5
|
+
// @ts-ignore
|
|
6
6
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
7
7
|
|
|
8
8
|
import { useTextWidth } from "../hooks/useTextWidth";
|
|
@@ -23,7 +23,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
23
23
|
|
|
24
24
|
const ref = useRef<HTMLStyleElement>(null);
|
|
25
25
|
|
|
26
|
-
const tempRef = useRef<SplitSide>();
|
|
26
|
+
const tempRef = useRef<SplitSide>(undefined);
|
|
27
27
|
|
|
28
28
|
const useDiffContextRef = useRef(useDiffContext);
|
|
29
29
|
|
|
@@ -66,7 +66,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
66
66
|
|
|
67
67
|
const lines = getUnifiedContentLine(diffFile);
|
|
68
68
|
|
|
69
|
-
const setStyle = (side
|
|
69
|
+
const setStyle = (side?: SplitSide) => {
|
|
70
70
|
if (!ref.current) return;
|
|
71
71
|
if (!side) {
|
|
72
72
|
ref.current.textContent = "";
|
|
@@ -77,7 +77,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
const onMouseDown: MouseEventHandler<HTMLTableSectionElement> = (e) => {
|
|
80
|
-
let ele = e.target;
|
|
80
|
+
let ele: Element | null = e.target as Element;
|
|
81
81
|
|
|
82
82
|
// need remove all the selection
|
|
83
83
|
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
@@ -149,21 +149,21 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
149
149
|
index={item.index}
|
|
150
150
|
lineNumber={item.lineNumber}
|
|
151
151
|
diffFile={diffFile}
|
|
152
|
-
enableWrap={enableWrap}
|
|
153
|
-
enableHighlight={enableHighlight}
|
|
154
|
-
enableAddWidget={enableAddWidget}
|
|
152
|
+
enableWrap={!!enableWrap}
|
|
153
|
+
enableHighlight={!!enableHighlight}
|
|
154
|
+
enableAddWidget={!!enableAddWidget}
|
|
155
155
|
/>
|
|
156
156
|
<DiffUnifiedWidgetLine
|
|
157
157
|
index={item.index}
|
|
158
158
|
lineNumber={item.lineNumber}
|
|
159
159
|
diffFile={diffFile}
|
|
160
|
-
enableWrap={enableWrap}
|
|
160
|
+
enableWrap={!!enableWrap}
|
|
161
161
|
/>
|
|
162
162
|
<DiffUnifiedExtendLine
|
|
163
163
|
index={item.index}
|
|
164
164
|
lineNumber={item.lineNumber}
|
|
165
165
|
diffFile={diffFile}
|
|
166
|
-
enableWrap={enableWrap}
|
|
166
|
+
enableWrap={!!enableWrap}
|
|
167
167
|
/>
|
|
168
168
|
</Fragment>
|
|
169
169
|
))}
|
|
@@ -55,10 +55,10 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
55
55
|
<div className="diff-line-widget-wrapper sticky left-0 z-[1]" style={{ width }}>
|
|
56
56
|
{(enableWrap ? true : width > 0) &&
|
|
57
57
|
oldWidget &&
|
|
58
|
-
renderWidgetLine?.({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })}
|
|
58
|
+
renderWidgetLine?.({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber ?? -1, onClose })}
|
|
59
59
|
{(enableWrap ? true : width > 0) &&
|
|
60
60
|
newWidget &&
|
|
61
|
-
renderWidgetLine?.({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose })}
|
|
61
|
+
renderWidgetLine?.({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber ?? -1, onClose })}
|
|
62
62
|
</div>
|
|
63
63
|
</td>
|
|
64
64
|
</tr>
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { DiffFile, _cacheMap, SplitSide, highlighter as buildInHighlighter } from "@git-diff-view/core";
|
|
4
4
|
import { diffFontSizeName, DiffModeEnum } from "@git-diff-view/utils";
|
|
5
5
|
import { memo, useEffect, useMemo, forwardRef, useImperativeHandle, useRef } from "react";
|
|
6
|
-
import * as React from "react";
|
|
7
6
|
|
|
8
7
|
import { useIsMounted } from "../hooks/useIsMounted";
|
|
9
8
|
import { useUnmount } from "../hooks/useUnmount";
|
|
@@ -16,7 +15,7 @@ import { createDiffConfigStore } from "./tools";
|
|
|
16
15
|
|
|
17
16
|
import type { createDiffWidgetStore } from "./tools";
|
|
18
17
|
import type { DiffHighlighter, DiffHighlighterLang } from "@git-diff-view/core";
|
|
19
|
-
import type { CSSProperties, ForwardedRef, ReactNode, RefObject } from "react";
|
|
18
|
+
import type { CSSProperties, ForwardedRef, JSX, ReactNode, RefObject } from "react";
|
|
20
19
|
|
|
21
20
|
_cacheMap.name = "@git-diff-view/react";
|
|
22
21
|
|
|
@@ -90,7 +89,7 @@ type DiffViewProps_2<T> = Omit<DiffViewProps<T>, "data"> & {
|
|
|
90
89
|
const InternalDiffView = <T extends unknown>(
|
|
91
90
|
props: Omit<DiffViewProps<T>, "data" | "registerHighlighter"> & {
|
|
92
91
|
isMounted: boolean;
|
|
93
|
-
wrapperRef
|
|
92
|
+
wrapperRef: RefObject<HTMLDivElement | null>;
|
|
94
93
|
}
|
|
95
94
|
) => {
|
|
96
95
|
const {
|
|
@@ -111,7 +110,7 @@ const InternalDiffView = <T extends unknown>(
|
|
|
111
110
|
isMounted,
|
|
112
111
|
} = props;
|
|
113
112
|
|
|
114
|
-
const diffFileId = useMemo(() => diffFile
|
|
113
|
+
const diffFileId = useMemo(() => diffFile!.getId(), [diffFile]);
|
|
115
114
|
|
|
116
115
|
// performance optimization
|
|
117
116
|
const useDiffContext = useMemo(
|
|
@@ -160,15 +159,15 @@ const InternalDiffView = <T extends unknown>(
|
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
if (diffViewAddWidget !== enableAddWidget) {
|
|
163
|
-
setEnableAddWidget(diffViewAddWidget);
|
|
162
|
+
setEnableAddWidget(!!diffViewAddWidget);
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
if (diffViewHighlight !== enableHighlight) {
|
|
167
|
-
setEnableHighlight(diffViewHighlight);
|
|
166
|
+
setEnableHighlight(!!diffViewHighlight);
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
if (diffViewWrap !== enableWrap) {
|
|
171
|
-
setEnableWrap(diffViewWrap);
|
|
170
|
+
setEnableWrap(!!diffViewWrap);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
if (extendData) {
|
|
@@ -211,7 +210,9 @@ const InternalDiffView = <T extends unknown>(
|
|
|
211
210
|
]);
|
|
212
211
|
|
|
213
212
|
useEffect(() => {
|
|
214
|
-
|
|
213
|
+
if (wrapperRef?.current) {
|
|
214
|
+
useDiffContext.getReadonlyState().setDom(wrapperRef?.current);
|
|
215
|
+
}
|
|
215
216
|
}, [useDiffContext, wrapperRef]);
|
|
216
217
|
|
|
217
218
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
@@ -221,9 +222,9 @@ const InternalDiffView = <T extends unknown>(
|
|
|
221
222
|
<div
|
|
222
223
|
className="diff-tailwindcss-wrapper"
|
|
223
224
|
data-component="git-diff-view"
|
|
224
|
-
data-theme={diffFile
|
|
225
|
+
data-theme={diffFile!._getTheme() || "light"}
|
|
225
226
|
data-version={__VERSION__}
|
|
226
|
-
data-highlighter={diffFile
|
|
227
|
+
data-highlighter={diffFile!._getHighlighterName()}
|
|
227
228
|
ref={wrapperRef}
|
|
228
229
|
>
|
|
229
230
|
<div
|
|
@@ -238,10 +239,10 @@ const InternalDiffView = <T extends unknown>(
|
|
|
238
239
|
className={"diff-view-wrapper" + (className ? ` ${className}` : "")}
|
|
239
240
|
style={style}
|
|
240
241
|
>
|
|
241
|
-
{diffViewMode & DiffModeEnum.Split ? (
|
|
242
|
-
<DiffSplitView diffFile={diffFile} />
|
|
242
|
+
{diffViewMode! & DiffModeEnum.Split ? (
|
|
243
|
+
<DiffSplitView diffFile={diffFile!} />
|
|
243
244
|
) : (
|
|
244
|
-
<DiffUnifiedView diffFile={diffFile} />
|
|
245
|
+
<DiffUnifiedView diffFile={diffFile!} />
|
|
245
246
|
)}
|
|
246
247
|
</div>
|
|
247
248
|
</div>
|
|
@@ -250,11 +251,11 @@ const InternalDiffView = <T extends unknown>(
|
|
|
250
251
|
);
|
|
251
252
|
};
|
|
252
253
|
|
|
253
|
-
const MemoedInternalDiffView = memo(InternalDiffView);
|
|
254
|
+
const MemoedInternalDiffView = memo(InternalDiffView) as typeof InternalDiffView;
|
|
254
255
|
|
|
255
256
|
const DiffViewWithRef = <T extends unknown>(
|
|
256
257
|
props: DiffViewProps<T>,
|
|
257
|
-
ref: ForwardedRef<{ getDiffFileInstance: () => DiffFile }>
|
|
258
|
+
ref: ForwardedRef<{ getDiffFileInstance: () => DiffFile | null }>
|
|
258
259
|
) => {
|
|
259
260
|
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile, ...restProps } = props;
|
|
260
261
|
|
|
@@ -282,9 +283,11 @@ const DiffViewWithRef = <T extends unknown>(
|
|
|
282
283
|
|
|
283
284
|
const diffFileRef = useRef(diffFile);
|
|
284
285
|
|
|
285
|
-
const wrapperRef = useRef<HTMLDivElement>();
|
|
286
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
286
287
|
|
|
288
|
+
// eslint-disable-next-line react-hooks/refs
|
|
287
289
|
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
290
|
+
// eslint-disable-next-line react-hooks/refs
|
|
288
291
|
diffFileRef.current.clear?.();
|
|
289
292
|
diffFileRef.current = diffFile;
|
|
290
293
|
}
|
|
@@ -371,14 +374,17 @@ const DiffViewWithRef = <T extends unknown>(
|
|
|
371
374
|
};
|
|
372
375
|
|
|
373
376
|
// type helper function
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
374
378
|
function ReactDiffView<T>(
|
|
375
|
-
props: DiffViewProps_1<T> & { ref?: ForwardedRef<{ getDiffFileInstance: () => DiffFile }> }
|
|
379
|
+
props: DiffViewProps_1<T> & { ref?: ForwardedRef<{ getDiffFileInstance: () => DiffFile | null }> }
|
|
376
380
|
): JSX.Element;
|
|
377
381
|
function ReactDiffView<T>(
|
|
378
|
-
props: DiffViewProps_2<T> & { ref?: ForwardedRef<{ getDiffFileInstance: () => DiffFile }> }
|
|
382
|
+
props: DiffViewProps_2<T> & { ref?: ForwardedRef<{ getDiffFileInstance: () => DiffFile | null }> }
|
|
379
383
|
): JSX.Element;
|
|
380
|
-
function ReactDiffView<T>(
|
|
381
|
-
|
|
384
|
+
function ReactDiffView<T>(
|
|
385
|
+
_props: DiffViewProps<T> & { ref?: ForwardedRef<{ getDiffFileInstance: () => DiffFile | null }> }
|
|
386
|
+
) {
|
|
387
|
+
return <></>;
|
|
382
388
|
}
|
|
383
389
|
|
|
384
390
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
@@ -4,6 +4,8 @@ import type { createDiffConfigStore } from "./tools";
|
|
|
4
4
|
|
|
5
5
|
export const DiffViewContext = createContext<{
|
|
6
6
|
useDiffContext: ReturnType<typeof createDiffConfigStore>;
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore
|
|
7
9
|
}>(null);
|
|
8
10
|
|
|
9
11
|
DiffViewContext.displayName = "DiffViewContext";
|