@git-diff-view/react 0.0.35 → 0.0.37
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 +38 -111
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +38 -111
- 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 -509
- package/dist/esm/index.mjs +39 -112
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +16 -11
- package/package.json +3 -3
- package/readme.md +123 -72
- package/src/_base.css +0 -1
- package/src/components/DiffAddWidget.tsx +4 -1
- 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 -509
- package/src/_base_pure.css +0 -2
- package/src/tailwind_pure.css +0 -3
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class File$1 {
|
|
|
14
14
|
readonly lang: DiffHighlighterLang | string;
|
|
15
15
|
readonly fileName?: string;
|
|
16
16
|
ast?: DiffAST;
|
|
17
|
+
theme?: "light" | "dark";
|
|
17
18
|
rawFile: Record<number, string>;
|
|
18
19
|
hasDoRaw: boolean;
|
|
19
20
|
rawLength?: number;
|
|
@@ -27,6 +28,9 @@ declare class File$1 {
|
|
|
27
28
|
highlighterName?: DiffHighlighter["name"];
|
|
28
29
|
highlighterType?: DiffHighlighter["type"];
|
|
29
30
|
maxLineNumber: number;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated
|
|
33
|
+
*/
|
|
30
34
|
enableTemplate: boolean;
|
|
31
35
|
static createInstance(data: File$1): File$1;
|
|
32
36
|
constructor(row: string, lang: DiffHighlighterLang, fileName?: string);
|
|
@@ -110,12 +114,9 @@ export declare class DiffFile {
|
|
|
110
114
|
initTheme(theme?: "light" | "dark"): void;
|
|
111
115
|
initRaw(): void;
|
|
112
116
|
initSyntax({ registerHighlighter }?: {
|
|
113
|
-
registerHighlighter?:
|
|
117
|
+
registerHighlighter?: DiffFileHighlighter;
|
|
114
118
|
}): void;
|
|
115
119
|
init(): void;
|
|
116
|
-
enableTemplate(): void;
|
|
117
|
-
disableTemplate(): void;
|
|
118
|
-
getIsEnableTemplate(): boolean;
|
|
119
120
|
buildSplitDiffLines(): void;
|
|
120
121
|
buildUnifiedDiffLines(): void;
|
|
121
122
|
getSplitLeftLine: (index: number) => SplitLineItem;
|
|
@@ -123,12 +124,12 @@ export declare class DiffFile {
|
|
|
123
124
|
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
|
|
124
125
|
getSplitRightLine: (index: number) => SplitLineItem;
|
|
125
126
|
getSplitHunkLine: (index: number) => DiffHunkItem;
|
|
126
|
-
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
|
|
127
|
+
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
|
|
127
128
|
getUnifiedLine: (index: number) => UnifiedLineItem;
|
|
128
129
|
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
|
|
129
130
|
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
|
|
130
131
|
getUnifiedHunkLine: (index: number) => DiffHunkItem;
|
|
131
|
-
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
|
|
132
|
+
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
|
|
132
133
|
onAllExpand: (mode: "split" | "unified") => void;
|
|
133
134
|
get hasExpandSplitAll(): boolean;
|
|
134
135
|
get hasExpandUnifiedAll(): boolean;
|
|
@@ -202,11 +203,11 @@ export declare class DiffFile {
|
|
|
202
203
|
};
|
|
203
204
|
version: string;
|
|
204
205
|
theme: "light" | "dark";
|
|
205
|
-
enableTemplate: boolean;
|
|
206
206
|
isFullMerge: boolean;
|
|
207
207
|
};
|
|
208
208
|
mergeBundle: (data: ReturnType<DiffFile["getBundle"]>, notifyUpdate?: boolean) => void;
|
|
209
209
|
_getHighlighterName: () => string;
|
|
210
|
+
_getHighlighterType: () => string;
|
|
210
211
|
_getIsPureDiffRender: () => boolean;
|
|
211
212
|
_getTheme: () => "light" | "dark";
|
|
212
213
|
_addClonedInstance: (instance: DiffFile) => void;
|
|
@@ -264,7 +265,6 @@ export declare class DiffFile {
|
|
|
264
265
|
};
|
|
265
266
|
version: string;
|
|
266
267
|
theme: "light" | "dark";
|
|
267
|
-
enableTemplate: boolean;
|
|
268
268
|
};
|
|
269
269
|
_mergeFullBundle: (data: ReturnType<DiffFile["_getFullBundle"]>, notifyUpdate?: boolean) => void;
|
|
270
270
|
_destroy: () => void;
|
|
@@ -312,11 +312,13 @@ export declare class DiffLine {
|
|
|
312
312
|
readonly noTrailingNewLine: boolean;
|
|
313
313
|
changes?: IRange;
|
|
314
314
|
diffChanges?: DiffRange;
|
|
315
|
+
_diffChanges?: DiffRange;
|
|
315
316
|
plainTemplate?: string;
|
|
316
317
|
plainTemplateMode?: "fast-diff" | "relative";
|
|
317
318
|
syntaxTemplate?: string;
|
|
319
|
+
syntaxTemplateName?: string;
|
|
318
320
|
syntaxTemplateMode?: "fast-diff" | "relative";
|
|
319
|
-
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");
|
|
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");
|
|
320
322
|
withNoTrailingNewLine(noTrailingNewLine: boolean): DiffLine;
|
|
321
323
|
isIncludeableLine(): boolean;
|
|
322
324
|
equals(other: DiffLine): boolean;
|
|
@@ -482,12 +484,14 @@ export declare const getPlainDiffTemplateByFastDiff: ({ diffLine, rawLine, opera
|
|
|
482
484
|
export declare const getPlainLineTemplate: (line: string) => string;
|
|
483
485
|
export declare const getSplitContentLines: (diffFile: DiffFile) => DiffSplitContentLineItem[];
|
|
484
486
|
export declare const getSplitLines: (diffFile: DiffFile) => DiffSplitLineItem[];
|
|
485
|
-
export declare const getSyntaxDiffTemplate: ({ diffLine, syntaxLine, operator, }: {
|
|
487
|
+
export declare const getSyntaxDiffTemplate: ({ diffFile, diffLine, syntaxLine, operator, }: {
|
|
488
|
+
diffFile: DiffFile;
|
|
486
489
|
diffLine: DiffLine;
|
|
487
490
|
syntaxLine: SyntaxLine;
|
|
488
491
|
operator: "add" | "del";
|
|
489
492
|
}) => void;
|
|
490
|
-
export declare const getSyntaxDiffTemplateByFastDiff: ({ diffLine, syntaxLine, operator, }: {
|
|
493
|
+
export declare const getSyntaxDiffTemplateByFastDiff: ({ diffFile, diffLine, syntaxLine, operator, }: {
|
|
494
|
+
diffFile: DiffFile;
|
|
491
495
|
diffLine: DiffLine;
|
|
492
496
|
syntaxLine: SyntaxLine;
|
|
493
497
|
operator: "add" | "del";
|
|
@@ -714,6 +718,7 @@ export interface UnifiedLineItem {
|
|
|
714
718
|
_isHidden?: boolean;
|
|
715
719
|
}
|
|
716
720
|
export type DiffAST = Root;
|
|
721
|
+
export type DiffFileHighlighter = Omit<DiffHighlighter, "getHighlighterEngine">;
|
|
717
722
|
export type DiffHighlighter = {
|
|
718
723
|
name: string;
|
|
719
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.37",
|
|
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.36",
|
|
65
65
|
"@types/hast": "^3.0.0",
|
|
66
66
|
"fast-diff": "^1.3.0",
|
|
67
67
|
"highlight.js": "^11.11.0",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"scripts": {
|
|
84
84
|
"gen:type": "dts-bundle-generator -o index.d.ts dist/types/index.d.ts",
|
|
85
85
|
"gen:css1": "postcss src/tailwind.css -o dist/css/diff-view.css",
|
|
86
|
-
"gen:css2": "postcss src/
|
|
86
|
+
"gen:css2": "postcss src/tailwind.css -o dist/css/diff-view-pure.css",
|
|
87
87
|
"gen:css": "npm run gen:css1 && npm run gen:css2"
|
|
88
88
|
}
|
|
89
89
|
}
|
package/readme.md
CHANGED
|
@@ -1,103 +1,154 @@
|
|
|
1
|
-
|
|
1
|
+
# @git-diff-view/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> A high-performance React diff view component with GitHub-style UI
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@git-diff-view/react)
|
|
6
|
+
[](https://www.npmjs.com/package/@git-diff-view/react)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ✅ Split & Unified views
|
|
11
|
+
- ✅ Syntax highlighting with full context
|
|
12
|
+
- ✅ Light & Dark themes
|
|
13
|
+
- ✅ SSR & RSC support
|
|
14
|
+
- ✅ Widget & extend data system
|
|
15
|
+
- ✅ High performance with Web Worker support
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @git-diff-view/react
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @git-diff-view/react
|
|
23
|
+
# or
|
|
24
|
+
yarn add @git-diff-view/react
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
8
30
|
|
|
9
31
|
```tsx
|
|
10
32
|
import { DiffView, DiffModeEnum } from "@git-diff-view/react";
|
|
11
33
|
import "@git-diff-view/react/styles/diff-view.css";
|
|
12
34
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
diffViewAddWidget
|
|
28
|
-
onAddWidgetClick={({ side, lineNumber }) => void}
|
|
29
|
-
renderWidgetLine={({ onClose, side, lineNumber }) => ReactNode}
|
|
30
|
-
/>
|
|
31
|
-
|
|
35
|
+
function MyDiffView() {
|
|
36
|
+
return (
|
|
37
|
+
<DiffView
|
|
38
|
+
data={{
|
|
39
|
+
oldFile: { fileName: "old.ts", content: "..." },
|
|
40
|
+
newFile: { fileName: "new.ts", content: "..." },
|
|
41
|
+
hunks: ["..."]
|
|
42
|
+
}}
|
|
43
|
+
diffViewMode={DiffModeEnum.Split}
|
|
44
|
+
diffViewTheme="dark"
|
|
45
|
+
diffViewHighlight
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
32
49
|
```
|
|
33
50
|
|
|
34
|
-
|
|
51
|
+
### Advanced Usage with DiffFile
|
|
52
|
+
|
|
53
|
+
**File Comparison Mode**
|
|
35
54
|
|
|
36
55
|
```tsx
|
|
37
|
-
|
|
56
|
+
import { DiffView } from "@git-diff-view/react";
|
|
38
57
|
import { DiffFile, generateDiffFile } from "@git-diff-view/file";
|
|
58
|
+
import "@git-diff-view/react/styles/diff-view.css";
|
|
59
|
+
|
|
39
60
|
const file = generateDiffFile(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
data?.newFile?.content || "",
|
|
44
|
-
data?.oldFile?.fileLang || "",
|
|
45
|
-
data?.newFile?.fileLang || ""
|
|
61
|
+
"old.ts", oldContent,
|
|
62
|
+
"new.ts", newContent,
|
|
63
|
+
"typescript", "typescript"
|
|
46
64
|
);
|
|
47
|
-
file.initTheme('
|
|
65
|
+
file.initTheme('dark');
|
|
48
66
|
file.init();
|
|
49
67
|
file.buildSplitDiffLines();
|
|
50
|
-
file.buildUnifiedDiffLines();
|
|
51
68
|
|
|
52
|
-
|
|
69
|
+
<DiffView diffFile={file} />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Git Diff Mode**
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { DiffView } from "@git-diff-view/react";
|
|
53
76
|
import { DiffFile } from "@git-diff-view/core";
|
|
77
|
+
import "@git-diff-view/react/styles/diff-view.css";
|
|
78
|
+
|
|
54
79
|
const file = new DiffFile(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
oldFileName,
|
|
81
|
+
oldContent,
|
|
82
|
+
newFileName,
|
|
83
|
+
newContent,
|
|
84
|
+
hunks,
|
|
85
|
+
oldFileLang,
|
|
86
|
+
newFileLang
|
|
62
87
|
);
|
|
63
|
-
file.initTheme('
|
|
88
|
+
file.initTheme('dark');
|
|
64
89
|
file.init();
|
|
65
90
|
file.buildSplitDiffLines();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// use current data to render
|
|
69
|
-
<DiffView diffFile={file} {...props} />;
|
|
70
|
-
// or use the bundle data to render, eg: postMessage/httpRequest
|
|
71
|
-
const bundle = file.getBundle();
|
|
72
|
-
const diffFile = DiffFile.createInstance(data || {}, bundle);
|
|
73
|
-
<DiffView diffFile={diffFile} {...props} />;
|
|
91
|
+
|
|
92
|
+
<DiffView diffFile={file} />
|
|
74
93
|
```
|
|
75
|
-
### example
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
#### [react-ssr-example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/next-page-example)
|
|
79
|
-
#### [react-rsc-example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/next-app-example)
|
|
95
|
+
## Styling
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
```tsx
|
|
98
|
+
// Default styles with Tailwind (next release will be pure CSS)
|
|
99
|
+
import "@git-diff-view/react/styles/diff-view.css";
|
|
100
|
+
|
|
101
|
+
// Pure CSS (no Tailwind conflicts)
|
|
102
|
+
import "@git-diff-view/react/styles/diff-view-pure.css";
|
|
103
|
+
```
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-

|
|
85
|
-

|
|
105
|
+
## API Reference
|
|
86
106
|
|
|
87
107
|
### Props
|
|
88
108
|
|
|
89
|
-
|
|
|
90
|
-
|
|
91
|
-
| data
|
|
92
|
-
| diffFile
|
|
93
|
-
|
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
| onAddWidgetClick |
|
|
109
|
+
| Prop | Type | Description |
|
|
110
|
+
|------|------|-------------|
|
|
111
|
+
| `data` | `DiffData` | Diff data with `oldFile`, `newFile`, and `hunks` |
|
|
112
|
+
| `diffFile` | `DiffFile` | Pre-processed diff file instance |
|
|
113
|
+
| `diffViewMode` | `Split \| Unified` | View mode (default: `Split`) |
|
|
114
|
+
| `diffViewTheme` | `light \| dark` | Theme (default: `light`) |
|
|
115
|
+
| `diffViewHighlight` | `boolean` | Enable syntax highlighting |
|
|
116
|
+
| `diffViewWrap` | `boolean` | Enable line wrapping |
|
|
117
|
+
| `diffViewFontSize` | `number` | Font size in pixels |
|
|
118
|
+
| `diffViewAddWidget` | `boolean` | Enable widget button |
|
|
119
|
+
| `renderWidgetLine` | `(props) => ReactNode` | Custom widget renderer |
|
|
120
|
+
| `renderExtendLine` | `(props) => ReactNode` | Custom extend data renderer |
|
|
121
|
+
| `extendData` | `ExtendData` | Additional data per line |
|
|
122
|
+
| `onAddWidgetClick` | `(props) => void` | Widget button click handler |
|
|
123
|
+
|
|
124
|
+
### DiffData Type
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
type DiffData = {
|
|
128
|
+
oldFile?: {
|
|
129
|
+
fileName?: string | null;
|
|
130
|
+
fileLang?: string | null;
|
|
131
|
+
content?: string | null;
|
|
132
|
+
};
|
|
133
|
+
newFile?: {
|
|
134
|
+
fileName?: string | null;
|
|
135
|
+
fileLang?: string | null;
|
|
136
|
+
content?: string | null;
|
|
137
|
+
};
|
|
138
|
+
hunks: string[];
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Examples
|
|
143
|
+
|
|
144
|
+
- [Basic React Example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/react-example)
|
|
145
|
+
- [Next.js SSR Example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/next-page-example)
|
|
146
|
+
- [Next.js RSC Example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/next-app-example)
|
|
147
|
+
|
|
148
|
+
## Live Demo
|
|
149
|
+
|
|
150
|
+
Try it online: [https://mrwangjusttodo.github.io/git-diff-view](https://mrwangjusttodo.github.io/git-diff-view)
|
|
151
|
+
|
|
152
|
+
## License
|
|
103
153
|
|
|
154
|
+
MIT © [MrWangJustToDo](https://github.com/MrWangJustToDo)
|
package/src/_base.css
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { addWidgetBGName, addWidgetColorName, diffFontSizeName } from "@git-diff-view/utils";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { SplitSide } from "./DiffView";
|
|
5
|
+
|
|
5
6
|
import type { DiffFile } from "@git-diff-view/core";
|
|
6
7
|
|
|
7
8
|
export const DiffSplitAddWidget = ({
|
|
@@ -21,6 +22,7 @@ export const DiffSplitAddWidget = ({
|
|
|
21
22
|
}) => {
|
|
22
23
|
return (
|
|
23
24
|
<div
|
|
25
|
+
data-add-widget={SplitSide[side]}
|
|
24
26
|
className={
|
|
25
27
|
"diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
|
|
26
28
|
(className ? " " + className : "")
|
|
@@ -63,6 +65,7 @@ export const DiffUnifiedAddWidget = ({
|
|
|
63
65
|
}) => {
|
|
64
66
|
return (
|
|
65
67
|
<div
|
|
68
|
+
data-add-widget={SplitSide[side]}
|
|
66
69
|
className="diff-add-widget-wrapper invisible absolute left-[100%] translate-x-[-50%] select-none transition-transform hover:scale-110 group-hover:visible"
|
|
67
70
|
style={{
|
|
68
71
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|