Skip to content

Commit f7bdccf

Browse files
fix
1 parent d4ea4c2 commit f7bdccf

7 files changed

Lines changed: 518 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@git-diff-view/utils": "workspace:*",
3636
"@git-diff-view/cli": "workspace:*",
3737
"@git-diff-view/shiki": "workspace:*",
38+
"@git-diff-view/file": "workspace:*",
3839
"@rollup/plugin-alias": "^5.1.1",
3940
"@swc/core": "^1.10.15",
4041
"@types/lodash": "^4.17.15",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/cli",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.1",
6+
"version": "0.0.2",
77
"main": "index.mjs",
88
"type": "module",
99
"types": "index.d.ts",

packages/cli/readme.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## A Cli DiffView Component like GitHub, Easy to use and feature complete.
2+
3+
### Usage
4+
5+
#### There are two ways to use this component:
6+
7+
1. Use the `DiffView` component directly.
8+
9+
```tsx
10+
import { DiffView, DiffModeEnum } from "@git-diff-view/cli";
11+
12+
<DiffView<string>
13+
// use data
14+
data={{
15+
oldFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
16+
newFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
17+
hunks: string[];
18+
}}
19+
width={number}
20+
extendData={{oldFile: {10: {data: 'foo'}}, newFile: {20: {data: 'bar'}}}}
21+
renderExtendLine={({ data }) => ReactNode}
22+
diffViewHighlight={boolean}
23+
diffViewTabSpace={boolean}
24+
diffViewTabWidth={"small" | "medium" | "large"}
25+
diffViewMode={DiffModeEnum.Split | DiffModeEnum.Unified}
26+
diffViewTheme={'light' | 'dark'}
27+
/>
28+
29+
```
30+
31+
2. Use the `DiffView` component with `@git-diff-view/core` or `@git-diff-view/file`
32+
33+
```tsx
34+
// with @git-diff-view/file
35+
import { DiffFile, generateDiffFile } from "@git-diff-view/file";
36+
const file = generateDiffFile(
37+
data?.oldFile?.fileName || "",
38+
data?.oldFile?.content || "",
39+
data?.newFile?.fileName || "",
40+
data?.newFile?.content || "",
41+
data?.oldFile?.fileLang || "",
42+
data?.newFile?.fileLang || ""
43+
);
44+
file.init();
45+
file.buildSplitDiffLines();
46+
file.buildUnifiedDiffLines();
47+
48+
// with @git-diff-view/core
49+
import { DiffFile } from "@git-diff-view/core";
50+
const file = new DiffFile(
51+
data?.oldFile?.fileName || "",
52+
data?.oldFile?.content || "",
53+
data?.newFile?.fileName || "",
54+
data?.newFile?.content || "",
55+
data?.hunks || [],
56+
data?.oldFile?.fileLang || "",
57+
data?.newFile?.fileLang || ""
58+
);
59+
file.init();
60+
file.buildSplitDiffLines();
61+
file.buildUnifiedDiffLines();
62+
63+
// use current data to render
64+
<DiffView diffFile={file} {...props} />;
65+
// or use the bundle data to render, eg: postMessage/httpRequest
66+
const bundle = file.getBundle();
67+
const diffFile = DiffFile.createInstance(data || {}, bundle);
68+
<DiffView diffFile={diffFile} {...props} />;
69+
```

packages/cli/src/components/DiffContent.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,10 @@ const DiffString = ({
216216
}
217217
return <Text key={index}>{char}</Text>;
218218
})}
219+
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
220+
<Text wrap="truncate">{"\\ No newline at end of file".padEnd(width - 1)}</Text>
221+
)}
219222
</Box>
220-
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
221-
<Box width={width - 1} backgroundColor={bg}>
222-
<Text wrap="truncate">{"\\ No newline at end of file".padEnd(width)}</Text>
223-
</Box>
224-
)}
225223
</>
226224
);
227225
}
@@ -530,12 +528,10 @@ const DiffSyntax = ({
530528
);
531529
}
532530
})}
531+
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
532+
<Text wrap="truncate">{"\\ No newline at end of file".padEnd(width - 1)}</Text>
533+
)}
533534
</Box>
534-
{isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (
535-
<Box width={width - 1} backgroundColor={bg}>
536-
<Text wrap="truncate">{"\\ No newline at end of file".padEnd(width)}</Text>
537-
</Box>
538-
)}
539535
</>
540536
);
541537
}

0 commit comments

Comments
 (0)