@git-diff-view/react 0.0.30 → 0.0.32
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 +63 -30
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +63 -30
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +6 -9
- package/dist/css/diff-view.css +6 -9
- package/dist/esm/index.mjs +63 -30
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +23 -4
- package/package.json +2 -2
- package/src/_com.css +4 -0
- package/src/components/DiffAddWidget.tsx +3 -1
- package/src/components/DiffSplitContentLineNormal.tsx +0 -1
- package/src/components/DiffSplitContentLineWrap.tsx +4 -2
- package/src/components/DiffSplitViewNormal.tsx +1 -1
- package/src/components/DiffSplitViewWrap.tsx +1 -1
- package/src/components/DiffUnifiedExtendLine.tsx +9 -3
- package/src/components/DiffUnifiedView.tsx +13 -3
- package/src/components/DiffUnifiedWidgetLine.tsx +10 -4
- package/src/components/DiffView.tsx +12 -4
- package/src/components/tools.ts +6 -0
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +22 -4
- package/src/hooks/useDomWidth.ts +10 -3
- package/src/hooks/useSyncHeight.ts +10 -3
- package/styles/diff-view-pure.css +6 -9
- package/styles/diff-view.css +6 -9
- package/src/components/DiffContent_v2.tsx +0 -338
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
import { Root } from 'hast';
|
|
3
4
|
import { CSSProperties, ForwardedRef, ReactNode, RefObject } from 'react';
|
|
4
5
|
|
|
5
6
|
declare class Cache$1<K, V> extends Map<K, V> {
|
|
@@ -276,8 +277,10 @@ export declare class DiffLine {
|
|
|
276
277
|
changes?: IRange;
|
|
277
278
|
diffChanges?: DiffRange;
|
|
278
279
|
plainTemplate?: string;
|
|
280
|
+
plainTemplateMode?: "fast-diff" | "relative";
|
|
279
281
|
syntaxTemplate?: string;
|
|
280
|
-
|
|
282
|
+
syntaxTemplateMode?: "fast-diff" | "relative";
|
|
283
|
+
constructor(text: string, type: DiffLineType, originalLineNumber: number | null, oldLineNumber: number | null, newLineNumber: number | null, noTrailingNewLine?: boolean, changes?: IRange, diffChanges?: DiffRange, plainTemplate?: string, plainTemplateMode?: "fast-diff" | "relative", syntaxTemplate?: string, syntaxTemplateMode?: "fast-diff" | "relative");
|
|
281
284
|
withNoTrailingNewLine(noTrailingNewLine: boolean): DiffLine;
|
|
282
285
|
isIncludeableLine(): boolean;
|
|
283
286
|
equals(other: DiffLine): boolean;
|
|
@@ -426,6 +429,7 @@ export declare const checkCurrentLineIsHidden: (diffFile: DiffFile, lineNumber:
|
|
|
426
429
|
unified: boolean;
|
|
427
430
|
};
|
|
428
431
|
export declare const checkDiffLineIncludeChange: (diffLine?: DiffLine) => boolean;
|
|
432
|
+
export declare const defaultTransform: (content: string) => string;
|
|
429
433
|
export declare const disableCache: () => void;
|
|
430
434
|
export declare const getCurrentComposeLength: () => number;
|
|
431
435
|
export declare const getDiffRange: (additions: DiffLine[], deletions: DiffLine[], { getAdditionRaw, getDeletionRaw, getAdditionSyntax, getDeletionSyntax, }: {
|
|
@@ -434,12 +438,18 @@ export declare const getDiffRange: (additions: DiffLine[], deletions: DiffLine[]
|
|
|
434
438
|
getAdditionSyntax: (lineNumber: number) => SyntaxLineWithTemplate;
|
|
435
439
|
getDeletionSyntax: (lineNumber: number) => SyntaxLineWithTemplate;
|
|
436
440
|
}) => void;
|
|
441
|
+
export declare const getEnableFastDiffTemplate: () => boolean;
|
|
437
442
|
export declare const getLang: (fileName: string) => string;
|
|
438
443
|
export declare const getPlainDiffTemplate: ({ diffLine, rawLine, operator, }: {
|
|
439
444
|
diffLine: DiffLine;
|
|
440
445
|
rawLine: string;
|
|
441
446
|
operator: "add" | "del";
|
|
442
447
|
}) => void;
|
|
448
|
+
export declare const getPlainDiffTemplateByFastDiff: ({ diffLine, rawLine, operator, }: {
|
|
449
|
+
diffLine: DiffLine;
|
|
450
|
+
rawLine: string;
|
|
451
|
+
operator: "add" | "del";
|
|
452
|
+
}) => void;
|
|
443
453
|
export declare const getPlainLineTemplate: (line: string) => string;
|
|
444
454
|
export declare const getSplitContentLines: (diffFile: DiffFile) => DiffSplitContentLineItem[];
|
|
445
455
|
export declare const getSplitLines: (diffFile: DiffFile) => DiffSplitLineItem[];
|
|
@@ -448,6 +458,11 @@ export declare const getSyntaxDiffTemplate: ({ diffLine, syntaxLine, operator, }
|
|
|
448
458
|
syntaxLine: SyntaxLineWithTemplate;
|
|
449
459
|
operator: "add" | "del";
|
|
450
460
|
}) => void;
|
|
461
|
+
export declare const getSyntaxDiffTemplateByFastDiff: ({ diffLine, syntaxLine, operator, }: {
|
|
462
|
+
diffLine: DiffLine;
|
|
463
|
+
syntaxLine: SyntaxLineWithTemplate;
|
|
464
|
+
operator: "add" | "del";
|
|
465
|
+
}) => void;
|
|
451
466
|
export declare const getSyntaxLineTemplate: (line: SyntaxLine) => string;
|
|
452
467
|
export declare const getUnifiedContentLine: (diffFile: DiffFile) => DiffUnifiedContentLineItem[];
|
|
453
468
|
export declare const getUnifiedLines: (diffFile: DiffFile) => DiffUnifiedLineItem[];
|
|
@@ -496,6 +511,7 @@ export declare const processTransformForFile: (content: string) => string;
|
|
|
496
511
|
*/
|
|
497
512
|
export declare const processTransformTemplateContent: (content: string) => string;
|
|
498
513
|
export declare const resetDefaultComposeLength: () => void;
|
|
514
|
+
export declare const resetEnableFastDiffTemplate: () => void;
|
|
499
515
|
/**
|
|
500
516
|
* Resets all transformation functions to their default state and disables transformation.
|
|
501
517
|
*
|
|
@@ -505,6 +521,7 @@ export declare const resetDefaultComposeLength: () => void;
|
|
|
505
521
|
* ```
|
|
506
522
|
*/
|
|
507
523
|
export declare const resetTransform: () => void;
|
|
524
|
+
export declare const setEnableFastDiffTemplate: (enable: boolean) => void;
|
|
508
525
|
/**
|
|
509
526
|
* ⚠️ **WARNING: DANGEROUS OPERATION** ⚠️
|
|
510
527
|
*
|
|
@@ -617,7 +634,8 @@ export interface DiffRange {
|
|
|
617
634
|
readonly range: {
|
|
618
635
|
type: 1 | -1 | 0;
|
|
619
636
|
str: string;
|
|
620
|
-
|
|
637
|
+
startIndex: number;
|
|
638
|
+
endIndex: number;
|
|
621
639
|
length: number;
|
|
622
640
|
}[];
|
|
623
641
|
readonly hasLineChange?: boolean;
|
|
@@ -682,7 +700,7 @@ export interface UnifiedLineItem {
|
|
|
682
700
|
isHidden?: boolean;
|
|
683
701
|
_isHidden?: boolean;
|
|
684
702
|
}
|
|
685
|
-
export type DiffAST =
|
|
703
|
+
export type DiffAST = Root;
|
|
686
704
|
export type DiffHighlighter = {
|
|
687
705
|
name: string;
|
|
688
706
|
type: "class" | "style" | string;
|
|
@@ -780,7 +798,6 @@ export type SyntaxLine = {
|
|
|
780
798
|
export type SyntaxLineWithTemplate = SyntaxLine & {
|
|
781
799
|
template?: string;
|
|
782
800
|
};
|
|
783
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
784
801
|
export type SyntaxNode = {
|
|
785
802
|
type: string;
|
|
786
803
|
value: string;
|
|
@@ -804,6 +821,8 @@ declare const createDiffConfigStore: (props: DiffViewProps<any> & {
|
|
|
804
821
|
}, diffFileId: string) => import("reactivity-store").UseSelectorWithStore<{
|
|
805
822
|
id: import("reactivity-store").Ref<string, string>;
|
|
806
823
|
setId: (_id: string) => string;
|
|
824
|
+
dom: import("reactivity-store").Ref<HTMLElement, HTMLElement>;
|
|
825
|
+
setDom: (_dom: HTMLElement) => HTMLElement;
|
|
807
826
|
mode: import("reactivity-store").Ref<DiffModeEnum, DiffModeEnum>;
|
|
808
827
|
setMode: (_mode: DiffModeEnum) => DiffModeEnum;
|
|
809
828
|
mounted: import("reactivity-store").Ref<boolean, boolean>;
|
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.32",
|
|
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.32",
|
|
65
65
|
"@types/hast": "^3.0.0",
|
|
66
66
|
"fast-diff": "^1.3.0",
|
|
67
67
|
"highlight.js": "^11.11.0",
|
package/src/_com.css
CHANGED
|
@@ -28,6 +28,7 @@ export const DiffSplitAddWidget = ({
|
|
|
28
28
|
style={{
|
|
29
29
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
30
30
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
31
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
31
32
|
}}
|
|
32
33
|
>
|
|
33
34
|
<button
|
|
@@ -62,10 +63,11 @@ export const DiffUnifiedAddWidget = ({
|
|
|
62
63
|
}) => {
|
|
63
64
|
return (
|
|
64
65
|
<div
|
|
65
|
-
className="diff-add-widget-wrapper invisible absolute left-[100%]
|
|
66
|
+
className="diff-add-widget-wrapper invisible absolute left-[100%] translate-x-[-50%] select-none transition-transform hover:scale-110 group-hover:visible"
|
|
66
67
|
style={{
|
|
67
68
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
68
69
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
70
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
69
71
|
}}
|
|
70
72
|
>
|
|
71
73
|
<button
|
|
@@ -13,7 +13,6 @@ import { SplitSide } from "..";
|
|
|
13
13
|
|
|
14
14
|
import { DiffSplitAddWidget } from "./DiffAddWidget";
|
|
15
15
|
import { DiffContent } from "./DiffContent";
|
|
16
|
-
// import { DiffContent_v2 } from "./DiffContent_v2";
|
|
17
16
|
import { useDiffViewContext } from "./DiffViewContext";
|
|
18
17
|
import { useDiffWidgetContext } from "./DiffWidgetContext";
|
|
19
18
|
|
|
@@ -13,7 +13,6 @@ import { SplitSide } from "..";
|
|
|
13
13
|
|
|
14
14
|
import { DiffSplitAddWidget } from "./DiffAddWidget";
|
|
15
15
|
import { DiffContent } from "./DiffContent";
|
|
16
|
-
// import { DiffContent_v2 } from "./DiffContent_v2";
|
|
17
16
|
import { useDiffViewContext } from "./DiffViewContext";
|
|
18
17
|
import { useDiffWidgetContext } from "./DiffWidgetContext";
|
|
19
18
|
|
|
@@ -77,7 +76,10 @@ const InternalDiffSplitLine = ({
|
|
|
77
76
|
<td
|
|
78
77
|
className="diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top"
|
|
79
78
|
data-side={SplitSide[SplitSide.old]}
|
|
80
|
-
style={{
|
|
79
|
+
style={{
|
|
80
|
+
backgroundColor: oldLineNumberBG,
|
|
81
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
82
|
+
}}
|
|
81
83
|
>
|
|
82
84
|
{hasDiff && enableAddWidget && (
|
|
83
85
|
<DiffSplitAddWidget
|
|
@@ -51,7 +51,7 @@ const DiffSplitViewTable = ({
|
|
|
51
51
|
<th scope="col">{SplitSide[side]} line content</th>
|
|
52
52
|
</tr>
|
|
53
53
|
</thead>
|
|
54
|
-
<tbody className="diff-table-body leading-[1.
|
|
54
|
+
<tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
|
|
55
55
|
{lines.map((line) => (
|
|
56
56
|
<Fragment key={line.index}>
|
|
57
57
|
<DiffSplitHunkLine index={line.index} side={side} lineNumber={line.lineNumber} diffFile={diffFile} />
|
|
@@ -119,7 +119,7 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
|
|
|
119
119
|
<th scope="col">new line content</th>
|
|
120
120
|
</tr>
|
|
121
121
|
</thead>
|
|
122
|
-
<tbody className="diff-table-body leading-[1.
|
|
122
|
+
<tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
|
|
123
123
|
{lines.map((line) => (
|
|
124
124
|
<Fragment key={line.index}>
|
|
125
125
|
<DiffSplitHunkLine index={line.index} lineNumber={line.lineNumber} diffFile={diffFile} />
|
|
@@ -12,12 +12,14 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
12
12
|
index,
|
|
13
13
|
diffFile,
|
|
14
14
|
lineNumber,
|
|
15
|
+
enableWrap,
|
|
15
16
|
oldLineExtend,
|
|
16
17
|
newLineExtend,
|
|
17
18
|
}: {
|
|
18
19
|
index: number;
|
|
19
20
|
diffFile: DiffFile;
|
|
20
21
|
lineNumber: number;
|
|
22
|
+
enableWrap: boolean;
|
|
21
23
|
oldLineExtend: { data: any };
|
|
22
24
|
newLineExtend: { data: any };
|
|
23
25
|
}) => {
|
|
@@ -27,9 +29,10 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
27
29
|
|
|
28
30
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
29
31
|
|
|
32
|
+
// TODO use css variable to get width
|
|
30
33
|
const width = useDomWidth({
|
|
31
34
|
selector: ".unified-diff-table-wrapper",
|
|
32
|
-
enable: typeof renderExtendLine === "function",
|
|
35
|
+
enable: typeof renderExtendLine === "function" && !enableWrap,
|
|
33
36
|
});
|
|
34
37
|
|
|
35
38
|
if (!renderExtendLine) return null;
|
|
@@ -38,7 +41,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
38
41
|
<tr data-line={`${lineNumber}-extend`} data-state="extend" className="diff-line diff-line-extend">
|
|
39
42
|
<td className="diff-line-extend-content p-0 align-top" colSpan={2}>
|
|
40
43
|
<div className="diff-line-extend-wrapper sticky left-0 z-[1]" style={{ width }}>
|
|
41
|
-
{width > 0 &&
|
|
44
|
+
{(enableWrap ? true : width > 0) &&
|
|
42
45
|
oldLineExtend?.data !== undefined &&
|
|
43
46
|
oldLineExtend?.data !== null &&
|
|
44
47
|
renderExtendLine?.({
|
|
@@ -48,7 +51,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
48
51
|
data: oldLineExtend.data,
|
|
49
52
|
onUpdate: diffFile.notifyAll,
|
|
50
53
|
})}
|
|
51
|
-
{width > 0 &&
|
|
54
|
+
{(enableWrap ? true : width > 0) &&
|
|
52
55
|
newLineExtend?.data !== undefined &&
|
|
53
56
|
newLineExtend?.data !== null &&
|
|
54
57
|
renderExtendLine?.({
|
|
@@ -68,10 +71,12 @@ export const DiffUnifiedExtendLine = ({
|
|
|
68
71
|
index,
|
|
69
72
|
diffFile,
|
|
70
73
|
lineNumber,
|
|
74
|
+
enableWrap,
|
|
71
75
|
}: {
|
|
72
76
|
index: number;
|
|
73
77
|
diffFile: DiffFile;
|
|
74
78
|
lineNumber: number;
|
|
79
|
+
enableWrap: boolean;
|
|
75
80
|
}) => {
|
|
76
81
|
const { useDiffContext } = useDiffViewContext();
|
|
77
82
|
|
|
@@ -96,6 +101,7 @@ export const DiffUnifiedExtendLine = ({
|
|
|
96
101
|
index={index}
|
|
97
102
|
diffFile={diffFile}
|
|
98
103
|
lineNumber={lineNumber}
|
|
104
|
+
enableWrap={enableWrap}
|
|
99
105
|
oldLineExtend={oldLineExtend}
|
|
100
106
|
newLineExtend={newLineExtend}
|
|
101
107
|
/>
|
|
@@ -135,7 +135,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
135
135
|
<th scope="col">line content</th>
|
|
136
136
|
</tr>
|
|
137
137
|
</thead>
|
|
138
|
-
<tbody className="diff-table-body leading-[1.
|
|
138
|
+
<tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
|
|
139
139
|
{lines.map((item) => (
|
|
140
140
|
<Fragment key={item.index}>
|
|
141
141
|
<DiffUnifiedHunkLine index={item.index} lineNumber={item.lineNumber} diffFile={diffFile} />
|
|
@@ -147,8 +147,18 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
147
147
|
enableHighlight={enableHighlight}
|
|
148
148
|
enableAddWidget={enableAddWidget}
|
|
149
149
|
/>
|
|
150
|
-
<DiffUnifiedWidgetLine
|
|
151
|
-
|
|
150
|
+
<DiffUnifiedWidgetLine
|
|
151
|
+
index={item.index}
|
|
152
|
+
lineNumber={item.lineNumber}
|
|
153
|
+
diffFile={diffFile}
|
|
154
|
+
enableWrap={enableWrap}
|
|
155
|
+
/>
|
|
156
|
+
<DiffUnifiedExtendLine
|
|
157
|
+
index={item.index}
|
|
158
|
+
lineNumber={item.lineNumber}
|
|
159
|
+
diffFile={diffFile}
|
|
160
|
+
enableWrap={enableWrap}
|
|
161
|
+
/>
|
|
152
162
|
</Fragment>
|
|
153
163
|
))}
|
|
154
164
|
<DiffUnifiedHunkLine
|
|
@@ -12,10 +12,12 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
12
12
|
index,
|
|
13
13
|
diffFile,
|
|
14
14
|
lineNumber,
|
|
15
|
+
enableWrap,
|
|
15
16
|
}: {
|
|
16
17
|
index: number;
|
|
17
18
|
diffFile: DiffFile;
|
|
18
19
|
lineNumber: number;
|
|
20
|
+
enableWrap: boolean;
|
|
19
21
|
}) => {
|
|
20
22
|
const { useWidget } = useDiffWidgetContext();
|
|
21
23
|
|
|
@@ -42,7 +44,7 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
42
44
|
|
|
43
45
|
const width = useDomWidth({
|
|
44
46
|
selector: ".unified-diff-table-wrapper",
|
|
45
|
-
enable: typeof renderWidgetLine === "function",
|
|
47
|
+
enable: typeof renderWidgetLine === "function" && !enableWrap,
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
if (!renderWidgetLine) return null;
|
|
@@ -51,10 +53,10 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
51
53
|
<tr data-line={`${lineNumber}-widget`} data-state="widget" className="diff-line diff-line-widget">
|
|
52
54
|
<td className="diff-line-widget-content p-0" colSpan={2}>
|
|
53
55
|
<div className="diff-line-widget-wrapper sticky left-0 z-[1]" style={{ width }}>
|
|
54
|
-
{width > 0 &&
|
|
56
|
+
{(enableWrap ? true : width > 0) &&
|
|
55
57
|
oldWidget &&
|
|
56
58
|
renderWidgetLine?.({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })}
|
|
57
|
-
{width > 0 &&
|
|
59
|
+
{(enableWrap ? true : width > 0) &&
|
|
58
60
|
newWidget &&
|
|
59
61
|
renderWidgetLine?.({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose })}
|
|
60
62
|
</div>
|
|
@@ -67,10 +69,12 @@ export const DiffUnifiedWidgetLine = ({
|
|
|
67
69
|
index,
|
|
68
70
|
diffFile,
|
|
69
71
|
lineNumber,
|
|
72
|
+
enableWrap,
|
|
70
73
|
}: {
|
|
71
74
|
index: number;
|
|
72
75
|
diffFile: DiffFile;
|
|
73
76
|
lineNumber: number;
|
|
77
|
+
enableWrap: boolean;
|
|
74
78
|
}) => {
|
|
75
79
|
const { useWidget } = useDiffWidgetContext();
|
|
76
80
|
|
|
@@ -100,5 +104,7 @@ export const DiffUnifiedWidgetLine = ({
|
|
|
100
104
|
|
|
101
105
|
if (!currentIsShow) return null;
|
|
102
106
|
|
|
103
|
-
return
|
|
107
|
+
return (
|
|
108
|
+
<InternalDiffUnifiedWidgetLine index={index} diffFile={diffFile} lineNumber={lineNumber} enableWrap={enableWrap} />
|
|
109
|
+
);
|
|
104
110
|
};
|
|
@@ -210,6 +210,10 @@ const InternalDiffView = <T extends unknown>(
|
|
|
210
210
|
onCreateUseWidgetHook,
|
|
211
211
|
]);
|
|
212
212
|
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
useDiffContext.getReadonlyState().setDom(wrapperRef?.current);
|
|
215
|
+
}, [useDiffContext, wrapperRef]);
|
|
216
|
+
|
|
213
217
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
214
218
|
|
|
215
219
|
return (
|
|
@@ -299,19 +303,23 @@ const DiffViewWithRef = <T extends unknown>(
|
|
|
299
303
|
useEffect(() => {
|
|
300
304
|
if (!diffFile) return;
|
|
301
305
|
diffFile.initTheme(diffViewTheme);
|
|
306
|
+
|
|
302
307
|
diffFile.initRaw();
|
|
308
|
+
|
|
303
309
|
diffFile.buildSplitDiffLines();
|
|
310
|
+
|
|
304
311
|
diffFile.buildUnifiedDiffLines();
|
|
305
312
|
}, [diffFile, diffViewTheme]);
|
|
306
313
|
|
|
307
314
|
useEffect(() => {
|
|
308
315
|
if (!diffFile) return;
|
|
309
|
-
|
|
316
|
+
|
|
310
317
|
if (props.diffViewHighlight) {
|
|
311
318
|
diffFile.initSyntax({ registerHighlighter });
|
|
312
|
-
diffFile.notifyAll();
|
|
313
319
|
}
|
|
314
|
-
|
|
320
|
+
|
|
321
|
+
diffFile.notifyAll();
|
|
322
|
+
}, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
|
|
315
323
|
|
|
316
324
|
useEffect(() => {
|
|
317
325
|
if (!diffFile) return;
|
|
@@ -326,7 +334,7 @@ const DiffViewWithRef = <T extends unknown>(
|
|
|
326
334
|
const cb = diffFile.subscribe(init);
|
|
327
335
|
|
|
328
336
|
return cb;
|
|
329
|
-
}, [diffFile
|
|
337
|
+
}, [diffFile]);
|
|
330
338
|
|
|
331
339
|
// fix react strict mode error
|
|
332
340
|
useUnmount(() => (__DEV__ ? diffFile?._destroy?.() : diffFile?.clear?.()), [diffFile]);
|
package/src/components/tools.ts
CHANGED
|
@@ -5,6 +5,10 @@ import type { RefObject } from "react";
|
|
|
5
5
|
|
|
6
6
|
export const createDiffConfigStore = (props: DiffViewProps<any> & { isMounted: boolean }, diffFileId: string) => {
|
|
7
7
|
return createStore(() => {
|
|
8
|
+
const dom = ref<HTMLElement>();
|
|
9
|
+
|
|
10
|
+
const setDom = (_dom: HTMLElement) => (dom.value = _dom);
|
|
11
|
+
|
|
8
12
|
const id = ref(diffFileId);
|
|
9
13
|
|
|
10
14
|
const setId = (_id: string) => (id.value = _id);
|
|
@@ -85,6 +89,8 @@ export const createDiffConfigStore = (props: DiffViewProps<any> & { isMounted: b
|
|
|
85
89
|
return {
|
|
86
90
|
id,
|
|
87
91
|
setId,
|
|
92
|
+
dom,
|
|
93
|
+
setDom,
|
|
88
94
|
mode,
|
|
89
95
|
setMode,
|
|
90
96
|
mounted,
|
|
@@ -55,6 +55,8 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
55
55
|
|
|
56
56
|
const ref = useRef<HTMLStyleElement>();
|
|
57
57
|
|
|
58
|
+
const tempRef = useRef<SplitSide>();
|
|
59
|
+
|
|
58
60
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
59
61
|
|
|
60
62
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -105,13 +107,19 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
105
107
|
const state = ele.getAttribute("data-state");
|
|
106
108
|
const side = ele.getAttribute("data-side");
|
|
107
109
|
if (side) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
if (tempRef.current !== SplitSide[side]) {
|
|
111
|
+
tempRef.current = SplitSide[side];
|
|
112
|
+
setStyle(SplitSide[side]);
|
|
113
|
+
removeAllSelection();
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
if (state) {
|
|
112
117
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
if (tempRef.current !== undefined) {
|
|
119
|
+
tempRef.current = undefined;
|
|
120
|
+
setStyle(undefined);
|
|
121
|
+
removeAllSelection();
|
|
122
|
+
}
|
|
115
123
|
return;
|
|
116
124
|
} else {
|
|
117
125
|
return;
|
|
@@ -125,6 +133,16 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
|
|
|
125
133
|
return (
|
|
126
134
|
<div className="split-diff-view split-diff-view-normal flex w-full basis-[50%]">
|
|
127
135
|
<style data-select-style ref={ref} />
|
|
136
|
+
<style>
|
|
137
|
+
{`
|
|
138
|
+
.diff-tailwindcss-wrapper .diff-add-widget-wrapper.diff-add-widget-wrapper.diff-add-widget-wrapper {
|
|
139
|
+
transform: translate(-50%, -50%) !important;
|
|
140
|
+
}
|
|
141
|
+
.diff-tailwindcss-wrapper .diff-add-widget-wrapper.diff-add-widget-wrapper.diff-add-widget-wrapper:hover {
|
|
142
|
+
transform: translate(-50%, -50%) scale(1.1) !important;
|
|
143
|
+
}
|
|
144
|
+
`}
|
|
145
|
+
</style>
|
|
128
146
|
<div
|
|
129
147
|
className="old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden"
|
|
130
148
|
ref={ref1}
|
package/src/hooks/useDomWidth.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getElementRoot } from "@git-diff-view/utils";
|
|
1
2
|
import { useEffect, useState } from "react";
|
|
2
3
|
|
|
3
4
|
import { useDiffViewContext } from "../components/DiffViewContext";
|
|
@@ -12,11 +13,17 @@ export const useDomWidth = ({ selector, enable }: { selector: string; enable: bo
|
|
|
12
13
|
|
|
13
14
|
const { useDiffContext } = useDiffViewContext();
|
|
14
15
|
|
|
15
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
16
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
17
|
+
id: s.id,
|
|
18
|
+
mounted: s.mounted,
|
|
19
|
+
dom: s.dom,
|
|
20
|
+
}));
|
|
16
21
|
|
|
17
22
|
useEffect(() => {
|
|
18
23
|
if (enable) {
|
|
19
|
-
const
|
|
24
|
+
const rootDocument = getElementRoot(dom as HTMLDivElement);
|
|
25
|
+
|
|
26
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
20
27
|
|
|
21
28
|
const wrapper = container?.querySelector(selector);
|
|
22
29
|
|
|
@@ -61,7 +68,7 @@ export const useDomWidth = ({ selector, enable }: { selector: string; enable: bo
|
|
|
61
68
|
|
|
62
69
|
return () => cleanCb();
|
|
63
70
|
}
|
|
64
|
-
}, [selector, enable, id, mounted]);
|
|
71
|
+
}, [selector, enable, id, mounted, dom]);
|
|
65
72
|
|
|
66
73
|
return width;
|
|
67
74
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getElementRoot } from "@git-diff-view/utils";
|
|
1
2
|
import { useEffect } from "react";
|
|
2
3
|
|
|
3
4
|
import { useDiffViewContext } from "../components/DiffViewContext";
|
|
@@ -17,11 +18,17 @@ export const useSyncHeight = ({
|
|
|
17
18
|
}) => {
|
|
18
19
|
const { useDiffContext } = useDiffViewContext();
|
|
19
20
|
|
|
20
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
21
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
22
|
+
id: s.id,
|
|
23
|
+
mounted: s.mounted,
|
|
24
|
+
dom: s.dom,
|
|
25
|
+
}));
|
|
21
26
|
|
|
22
27
|
useEffect(() => {
|
|
23
28
|
if (enable) {
|
|
24
|
-
const
|
|
29
|
+
const rootDocument = getElementRoot(dom as HTMLDivElement);
|
|
30
|
+
|
|
31
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
25
32
|
|
|
26
33
|
const elements = Array.from(container?.querySelectorAll(selector) || []);
|
|
27
34
|
|
|
@@ -83,5 +90,5 @@ export const useSyncHeight = ({
|
|
|
83
90
|
return () => cleanCb();
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
}, [selector, enable, side, id, wrapper, mounted]);
|
|
93
|
+
}, [selector, enable, side, id, wrapper, mounted, dom]);
|
|
87
94
|
};
|
|
@@ -50,9 +50,6 @@
|
|
|
50
50
|
.diff-tailwindcss-wrapper .top-0 {
|
|
51
51
|
top: 0px;
|
|
52
52
|
}
|
|
53
|
-
.diff-tailwindcss-wrapper .top-\[1px\] {
|
|
54
|
-
top: 1px;
|
|
55
|
-
}
|
|
56
53
|
.diff-tailwindcss-wrapper .top-\[50\%\] {
|
|
57
54
|
top: 50%;
|
|
58
55
|
}
|
|
@@ -155,6 +152,9 @@
|
|
|
155
152
|
--tw-translate-y: -50%;
|
|
156
153
|
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
|
157
154
|
}
|
|
155
|
+
.diff-tailwindcss-wrapper .transform {
|
|
156
|
+
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
|
157
|
+
}
|
|
158
158
|
.diff-tailwindcss-wrapper .cursor-pointer {
|
|
159
159
|
cursor: pointer;
|
|
160
160
|
}
|
|
@@ -247,9 +247,6 @@
|
|
|
247
247
|
.diff-tailwindcss-wrapper .text-\[1\.2em\] {
|
|
248
248
|
font-size: 1.2em;
|
|
249
249
|
}
|
|
250
|
-
.diff-tailwindcss-wrapper .leading-\[1\.4\] {
|
|
251
|
-
line-height: 1.4;
|
|
252
|
-
}
|
|
253
250
|
.diff-tailwindcss-wrapper .leading-\[1\.6\] {
|
|
254
251
|
line-height: 1.6;
|
|
255
252
|
}
|
|
@@ -260,9 +257,6 @@
|
|
|
260
257
|
.diff-tailwindcss-wrapper .opacity-\[0\.5\] {
|
|
261
258
|
opacity: 0.5;
|
|
262
259
|
}
|
|
263
|
-
.diff-tailwindcss-wrapper .filter {
|
|
264
|
-
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
265
|
-
}
|
|
266
260
|
.diff-tailwindcss-wrapper .transition-transform {
|
|
267
261
|
transition-property: transform;
|
|
268
262
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
@@ -335,6 +329,9 @@
|
|
|
335
329
|
border-width: 0px;
|
|
336
330
|
text-align: left;
|
|
337
331
|
}
|
|
332
|
+
.diff-tailwindcss-wrapper td {
|
|
333
|
+
padding: 0;
|
|
334
|
+
}
|
|
338
335
|
.diff-tailwindcss-wrapper .diff-line-old-num,
|
|
339
336
|
.diff-tailwindcss-wrapper .diff-line-new-num,
|
|
340
337
|
.diff-tailwindcss-wrapper .diff-line-num {
|
package/styles/diff-view.css
CHANGED
|
@@ -556,9 +556,6 @@ video {
|
|
|
556
556
|
.diff-tailwindcss-wrapper .top-0 {
|
|
557
557
|
top: 0px;
|
|
558
558
|
}
|
|
559
|
-
.diff-tailwindcss-wrapper .top-\[1px\] {
|
|
560
|
-
top: 1px;
|
|
561
|
-
}
|
|
562
559
|
.diff-tailwindcss-wrapper .top-\[50\%\] {
|
|
563
560
|
top: 50%;
|
|
564
561
|
}
|
|
@@ -661,6 +658,9 @@ video {
|
|
|
661
658
|
--tw-translate-y: -50%;
|
|
662
659
|
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
|
663
660
|
}
|
|
661
|
+
.diff-tailwindcss-wrapper .transform {
|
|
662
|
+
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
|
663
|
+
}
|
|
664
664
|
.diff-tailwindcss-wrapper .cursor-pointer {
|
|
665
665
|
cursor: pointer;
|
|
666
666
|
}
|
|
@@ -753,9 +753,6 @@ video {
|
|
|
753
753
|
.diff-tailwindcss-wrapper .text-\[1\.2em\] {
|
|
754
754
|
font-size: 1.2em;
|
|
755
755
|
}
|
|
756
|
-
.diff-tailwindcss-wrapper .leading-\[1\.4\] {
|
|
757
|
-
line-height: 1.4;
|
|
758
|
-
}
|
|
759
756
|
.diff-tailwindcss-wrapper .leading-\[1\.6\] {
|
|
760
757
|
line-height: 1.6;
|
|
761
758
|
}
|
|
@@ -766,9 +763,6 @@ video {
|
|
|
766
763
|
.diff-tailwindcss-wrapper .opacity-\[0\.5\] {
|
|
767
764
|
opacity: 0.5;
|
|
768
765
|
}
|
|
769
|
-
.diff-tailwindcss-wrapper .filter {
|
|
770
|
-
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
771
|
-
}
|
|
772
766
|
.diff-tailwindcss-wrapper .transition-transform {
|
|
773
767
|
transition-property: transform;
|
|
774
768
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
@@ -841,6 +835,9 @@ video {
|
|
|
841
835
|
border-width: 0px;
|
|
842
836
|
text-align: left;
|
|
843
837
|
}
|
|
838
|
+
.diff-tailwindcss-wrapper td {
|
|
839
|
+
padding: 0;
|
|
840
|
+
}
|
|
844
841
|
.diff-tailwindcss-wrapper .diff-line-old-num,
|
|
845
842
|
.diff-tailwindcss-wrapper .diff-line-new-num,
|
|
846
843
|
.diff-tailwindcss-wrapper .diff-line-num {
|