Skip to content

Commit 31fcbbc

Browse files
doc
1 parent f0653bb commit 31fcbbc

24 files changed

+658
-69
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The most one component what easy to use and feature complete.
2626

2727
![GitHub compare](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/aa2e918498270f737d28e7531eab08fa3f1b8831/4.png)
2828

29-
## How to use
29+
## How to use (React / Vue / Solid / Svelte)
3030

3131
See example project [Example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui)
3232

@@ -170,15 +170,11 @@ const diffFile = DiffFile.createInstance(data || {}, bundle);
170170
| extendData | a list to store the extend data to show in the `Diff View`, type: {oldFile: {lineNumber: {data: any}}, newFile: {lineNumber: {data: any}}} |
171171
| diffViewFontSize | the fontSize for the DiffView component, type: number |
172172
| diffViewHighlight | enable syntax highlight, type: boolean |
173-
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` or `DiffModeEnum.Unified` |
173+
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` / `DiffModeEnum.Unified` |
174174
| diffViewWrap | enable code line auto wrap, type: boolean |
175-
| diffViewTheme | the theme for the DiffView component, type: `light` or `dark` |
175+
| diffViewTheme | the theme for the DiffView component, type: `light` / `dark` |
176176
| diffViewAddWidget| enable `addWidget` button, type: boolean |
177-
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" | "new", lineNumber: number }) => void` |
178-
179-
## Use in Vue
180-
181-
Same with the React, see [detail](https://github.com/MrWangJustToDo/git-diff-view/tree/main/packages/vue)
177+
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" / "new", lineNumber: number }) => void` |
182178

183179
## Development
184180

packages/cli/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@git-diff-view/cli",
3+
"description": "@git-diff-view/cli",
4+
"author": "MrWangJustToDo",
5+
"license": "MIT",
6+
"version": "0.0.1",
7+
"main": "index.mjs",
8+
"type": "module",
9+
"types": "index.d.ts",
10+
"files": [
11+
"src",
12+
"dist",
13+
"styles",
14+
"index.mjs",
15+
"index.d.ts"
16+
],
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/MrWangJustToDo/git-diff-view.git",
20+
"directory": "packages/cli"
21+
},
22+
"scripts": {
23+
"gen:type": "dts-bundle-generator -o index.d.ts dist/types/index.d.ts"
24+
},
25+
"homepage": "https://mrwangjusttodo.github.io/git-diff-view",
26+
"exports": {
27+
".": {
28+
"types": "./index.d.ts",
29+
"import": "./index.mjs"
30+
},
31+
"./package.json": "./package.json"
32+
},
33+
"keywords": [
34+
"diff component",
35+
"cli diff component"
36+
],
37+
"dependencies": {
38+
"@git-diff-view/core": "^0.0.29",
39+
"@types/hast": "^3.0.0",
40+
"highlight.js": "^11.11.0",
41+
"lowlight": "^3.3.0",
42+
"fast-diff": "^1.3.0",
43+
"reactivity-store": "^0.3.11"
44+
},
45+
"devDependencies": {
46+
"react": "^18.0.0"
47+
},
48+
"peerDependencies": {
49+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
50+
"ink": "^6.0.1"
51+
}
52+
}

packages/cli/src/index.tsx

Whitespace-only changes.

packages/cli/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": "src",
4+
"target": "ESNext",
5+
"esModuleInterop": true,
6+
"moduleResolution": "Bundler",
7+
"jsx": "react-jsx",
8+
"jsxImportSource": "@my-react/react"
9+
},
10+
"include": ["./src"],
11+
"exclude": ["node_modules"]
12+
}

packages/react/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ const diffFile = DiffFile.createInstance(data || {}, bundle);
9595
| extendData | a list to store the extend data to show in the `Diff View`, type: {oldFile: {lineNumber: {data: any}}, newFile: {lineNumber: {data: any}}} |
9696
| diffViewFontSize | the fontSize for the DiffView component, type: number |
9797
| diffViewHighlight | enable syntax highlight, type: boolean |
98-
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` or `DiffModeEnum.Unified` |
98+
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` / `DiffModeEnum.Unified` |
9999
| diffViewWrap | enable code line auto wrap, type: boolean |
100-
| diffViewTheme | the theme for the DiffView component, type: `light` or `dark` |
100+
| diffViewTheme | the theme for the DiffView component, type: `light` / `dark` |
101101
| diffViewAddWidget| enable `addWidget` button, type: boolean |
102-
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" | "new", lineNumber: number }) => void` |
102+
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" / "new", lineNumber: number }) => void` |
103103

packages/solid/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/solid",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.1",
6+
"version": "0.0.2",
77
"main": "./dist/solid-git-diff-view.mjs",
88
"type": "module",
99
"types": "index.d.ts",

packages/solid/readme.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## A Solid 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/solid";
11+
import "@git-diff-view/solid/styles/diff-view.css";
12+
13+
<DiffView<string>
14+
// use data
15+
data={{
16+
oldFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
17+
newFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
18+
hunks: string[];
19+
}}
20+
extendData={{oldFile: {10: {data: 'foo'}}, newFile: {20: {data: 'bar'}}}}
21+
renderExtendLine={({ data }) => JSXElement}
22+
diffViewFontSize={number}
23+
diffViewHighlight={boolean}
24+
diffViewMode={DiffModeEnum.Split | DiffModeEnum.Unified}
25+
diffViewWrap={boolean}
26+
diffViewTheme={'light' | 'dark'}
27+
diffViewAddWidget
28+
onAddWidgetClick={({ side, lineNumber }) => void}
29+
renderWidgetLine={({ onClose, side, lineNumber }) => JSXElement}
30+
/>
31+
32+
```
33+
34+
2. Use the `DiffView` component with `@git-diff-view/core` or `@git-diff-view/file`
35+
36+
```tsx
37+
// with @git-diff-view/file
38+
import { DiffFile, generateDiffFile } from "@git-diff-view/file";
39+
const file = generateDiffFile(
40+
data?.oldFile?.fileName || "",
41+
data?.oldFile?.content || "",
42+
data?.newFile?.fileName || "",
43+
data?.newFile?.content || "",
44+
data?.oldFile?.fileLang || "",
45+
data?.newFile?.fileLang || ""
46+
);
47+
file.initTheme('light' / 'dark');
48+
file.init();
49+
file.buildSplitDiffLines();
50+
file.buildUnifiedDiffLines();
51+
52+
// with @git-diff-view/core
53+
import { DiffFile } from "@git-diff-view/core";
54+
const file = new DiffFile(
55+
data?.oldFile?.fileName || "",
56+
data?.oldFile?.content || "",
57+
data?.newFile?.fileName || "",
58+
data?.newFile?.content || "",
59+
data?.hunks || [],
60+
data?.oldFile?.fileLang || "",
61+
data?.newFile?.fileLang || ""
62+
);
63+
file.initTheme('light' / 'dark');
64+
file.init();
65+
file.buildSplitDiffLines();
66+
file.buildUnifiedDiffLines();
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} />;
74+
```
75+
### example
76+
77+
#### [solid-example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/solid-example)
78+
79+
### Screen Shot
80+
81+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/aa2e918498270f737d28e7531eab08fa3f1b8831/1.png)
82+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/69c801e5eb5fcabc9c9655825eb1228f18dc1e0c/5.png)
83+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/aa2e918498270f737d28e7531eab08fa3f1b8831/theme.png)
84+
85+
### Props
86+
87+
| Props | Description |
88+
| :--------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
89+
| data | The diff data need to show, type: `{ oldFile: {fileName?: string, content?: string}, newFile: {fileName?: string, content?: string}, hunks: string[] }`, you can only pass hunks data, and the component will generate the oldFile and newFile data automatically |
90+
| diffFile | the target data to render |
91+
| renderWidgetLine | return a valid `solid` element to show the widget, this element will render when you click the `addWidget` button in the diff view |
92+
| renderExtendLine | return a valid `solid` element to show the extend data |
93+
| extendData | a list to store the extend data to show in the `Diff View`, type: {oldFile: {lineNumber: {data: any}}, newFile: {lineNumber: {data: any}}} |
94+
| diffViewFontSize | the fontSize for the DiffView component, type: number |
95+
| diffViewHighlight | enable syntax highlight, type: boolean |
96+
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` / `DiffModeEnum.Unified` |
97+
| diffViewWrap | enable code line auto wrap, type: boolean |
98+
| diffViewTheme | the theme for the DiffView component, type: `light` / `dark` |
99+
| diffViewAddWidget| enable `addWidget` button, type: boolean |
100+
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" / "new", lineNumber: number }) => void` |
101+

packages/svelte/README.md

Lines changed: 102 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,112 @@
1-
# Svelte library
1+
## A Svelte 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/svelte";
11+
import "@git-diff-view/Svelte/styles/diff-view.css";
12+
13+
<DiffView
14+
// use data
15+
data={{
16+
oldFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
17+
newFile?: { fileName?: string | null; fileLang?: string | null; content?: string | null };
18+
hunks: string[];
19+
}}
20+
extendData={{oldFile: {10: {data: 'foo'}}, newFile: {20: {data: 'bar'}}}}
21+
renderExtendLine=Snippet<[{
22+
lineNumber: number;
23+
side: SplitSide;
24+
data: string;
25+
diffFile: DiffFile;
26+
onUpdate: () => void;
27+
}]>
28+
diffViewFontSize={number}
29+
diffViewHighlight={boolean}
30+
diffViewMode={DiffModeEnum.Split | DiffModeEnum.Unified}
31+
diffViewWrap={boolean}
32+
diffViewTheme={'light' | 'dark'}
33+
diffViewAddWidget
34+
onAddWidgetClick={({ side, lineNumber }) => void}
35+
renderWidgetLine=Snippet<[{
36+
lineNumber: number;
37+
side: SplitSide;
38+
diffFile: DiffFile;
39+
onClose: () => void;
40+
}]>
41+
/>
242

3-
Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
4-
5-
Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
6-
7-
## Creating a project
8-
9-
If you're seeing this, you've probably already done this step. Congrats!
10-
11-
```bash
12-
# create a new project in the current directory
13-
npx sv create
14-
15-
# create a new project in my-app
16-
npx sv create my-app
1743
```
1844

19-
## Developing
20-
21-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22-
23-
```bash
24-
npm run dev
25-
26-
# or start the server and open the app in a new browser tab
27-
npm run dev -- --open
45+
2. Use the `DiffView` component with `@git-diff-view/core` or `@git-diff-view/file`
46+
47+
```tsx
48+
// with @git-diff-view/file
49+
import { DiffFile, generateDiffFile } from "@git-diff-view/file";
50+
const file = generateDiffFile(
51+
data?.oldFile?.fileName || "",
52+
data?.oldFile?.content || "",
53+
data?.newFile?.fileName || "",
54+
data?.newFile?.content || "",
55+
data?.oldFile?.fileLang || "",
56+
data?.newFile?.fileLang || ""
57+
);
58+
file.initTheme('light' / 'dark');
59+
file.init();
60+
file.buildSplitDiffLines();
61+
file.buildUnifiedDiffLines();
62+
63+
// with @git-diff-view/core
64+
import { DiffFile } from "@git-diff-view/core";
65+
const file = new DiffFile(
66+
data?.oldFile?.fileName || "",
67+
data?.oldFile?.content || "",
68+
data?.newFile?.fileName || "",
69+
data?.newFile?.content || "",
70+
data?.hunks || [],
71+
data?.oldFile?.fileLang || "",
72+
data?.newFile?.fileLang || ""
73+
);
74+
file.initTheme('light' / 'dark');
75+
file.init();
76+
file.buildSplitDiffLines();
77+
file.buildUnifiedDiffLines();
78+
79+
// use current data to render
80+
<DiffView diffFile={file} {...props} />;
81+
// or use the bundle data to render, eg: postMessage/httpRequest
82+
const bundle = file.getBundle();
83+
const diffFile = DiffFile.createInstance(data || {}, bundle);
84+
<DiffView diffFile={diffFile} {...props} />;
2885
```
86+
### example
2987

30-
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
88+
#### [svelte-example](https://github.com/MrWangJustToDo/git-diff-view/tree/main/ui/svelte-example)
3189

32-
## Building
90+
### Screen Shot
3391

34-
To build your library:
92+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/aa2e918498270f737d28e7531eab08fa3f1b8831/1.png)
93+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/69c801e5eb5fcabc9c9655825eb1228f18dc1e0c/5.png)
94+
![Screenshot](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/aa2e918498270f737d28e7531eab08fa3f1b8831/theme.png)
3595

36-
```bash
37-
npm run package
38-
```
96+
### Props
3997

40-
To create a production version of your showcase app:
98+
| Props | Description |
99+
| :--------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100+
| data | The diff data need to show, type: `{ oldFile: {fileName?: string, content?: string}, newFile: {fileName?: string, content?: string}, hunks: string[] }`, you can only pass hunks data, and the component will generate the oldFile and newFile data automatically |
101+
| diffFile | the target data to render |
102+
| renderWidgetLine | a valid `svelte` snippet to show the widget, this element will render when you click the `addWidget` button in the diff view |
103+
| renderExtendLine | a valid `svelte` snippet to show the extend data |
104+
| extendData | a list to store the extend data to show in the `Diff View`, type: {oldFile: {lineNumber: {data: any}}, newFile: {lineNumber: {data: any}}} |
105+
| diffViewFontSize | the fontSize for the DiffView component, type: number |
106+
| diffViewHighlight | enable syntax highlight, type: boolean |
107+
| diffViewMode | the mode for the DiffView component, type: `DiffModeEnum.Split` / `DiffModeEnum.Unified` |
108+
| diffViewWrap | enable code line auto wrap, type: boolean |
109+
| diffViewTheme | the theme for the DiffView component, type: `light` / `dark` |
110+
| diffViewAddWidget| enable `addWidget` button, type: boolean |
111+
| onAddWidgetClick | when the `addWidget` button clicked, type: `({ side: "old" / "new", lineNumber: number }) => void` |
41112

42-
```bash
43-
npm run build
44-
```
45-
46-
You can preview the production build with `npm run preview`.
47-
48-
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
49-
50-
## Publishing
51-
52-
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53-
54-
To publish your library to [npm](https://www.npmjs.com):
55-
56-
```bash
57-
npm publish
58-
```

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@git-diff-view/svelte",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"scripts": {
55
"dev": "vite dev",
66
"build": "npm run prepack",

0 commit comments

Comments
 (0)