Skip to content

Commit acab227

Browse files
Merge pull request #17 from MrWangJustToDo/feature/ssr
ssr impl
2 parents f50669a + 482384e commit acab227

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2576
-174
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ module.exports = {
55
},
66
// eslint will auto add `eslint-config` for a no scope package(which not start with '@' chart), so here use absolute file path
77
extends: [require.resolve("project-tool/baseLint")],
8-
ignorePatterns: ["dist", "dev", "scripts", "node_modules"],
8+
ignorePatterns: ["dist", "dev", "scripts", "node_modules", "next-app-example", "next-page-example"],
99
};

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
**/node_modules
2+
**/next-app-example
3+
**/next-page-example
24
**/dist
35
**/dev
46
**/*.md

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ a React/Vue component to show the `git diff`/`file diff` result, just like Githu
4747
+ [x] Show the `git diff` result
4848
+ [x] Support `Split View` and `Unified View`
4949
+ [x] Support `Warp` / `UnWarp` the code line
50-
+ [x] Support `light` / `dark` theme by default
50+
+ [x] Support `light` / `dark` theme by default (since v0.0.17)
5151
+ [x] Support `Syntax Highlight` with <b>`full syntax context`</b> (base on `hast` AST)
5252
+ [x] Support `Extend Data` component in the `Diff View`
5353
+ [x] Support `Widget` component in the `Diff View`
5454
+ [x] Support `Web Worker` / `Node Server` to improve performance
5555
+ [x] Support `React` and `Vue` component
5656
+ [x] Support compare by `@git-diff-view/core`(git diff) or `@git-diff-view/file`(file content)
5757
+ [x] Support `Diff Match Patch` to improve line diff (experimental)
58+
+ [x] Support `SSR` for `React` and `Vue` component (since v0.0.21)
59+
+ [x] Support `RSC` for `React` component (since v0.0.21)
5860
+ [ ] Support `Virtual Scroll` to improve performance
5961

6062

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"start:release": "ts-node ./scripts/release.ts",
1111
"dev:react": "cd ui/react-example && pnpm run dev",
1212
"dev:vue": "cd ui/vue-example && pnpm run dev",
13+
"dev:vue-ssr": "cd ui/vue-ssr-example && pnpm run dev",
14+
"dev:next-page": "cd ui/next-page-example && pnpm run dev",
15+
"dev:next-app": "cd ui/next-app-example && pnpm run dev",
1316
"build:react": "cd ui/react-example && pnpm run build",
1417
"pre:release": "pnpm run lint && pnpm run prettier && pnpm run clean && pnpm run build:packages",
1518
"release": "pnpm run pre:release && pnpm run start:release",

packages/core/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ export declare enum NewLineSymbol {
408408
CR = 2,
409409
LF = 3,
410410
NEWLINE = 4,
411-
NORMAL = 5
411+
NORMAL = 5,
412+
NULL = 6
412413
}
413414
export declare function _getAST(raw: string, fileName?: string, lang?: DiffHighlighterLang, theme?: "light" | "dark"): DiffAST;
414415
export declare function _getAST(raw: string, fileName?: string, lang?: string, theme?: "light" | "dark"): DiffAST;

packages/core/src/diff-file.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,19 @@ export class DiffFile {
628628
const maxOldFileLineNumber = this.#oldFileResult?.maxLineNumber || 0;
629629
const maxNewFileLineNumber = this.#newFileResult?.maxLineNumber || 0;
630630

631+
if (__DEV__ && !this.#oldFileResult && !this.#newFileResult) {
632+
console.error(
633+
"this instance can not `buildSplitDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
634+
);
635+
}
636+
631637
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
632638
const oldDiffLine = this.#getOldDiffLine(oldFileLineNumber);
633639
const newDiffLine = this.#getNewDiffLine(newFileLineNumber);
634640
const oldRawLine = this.#getOldRawLine(oldFileLineNumber);
635641
const newRawLine = this.#getNewRawLine(newFileLineNumber);
636-
const oldLineHasChange = oldDiffLine?.isIncludeableLine();
637-
const newLineHasChange = newDiffLine?.isIncludeableLine();
642+
const oldLineHasChange = DiffLine.prototype.isIncludeableLine.call(oldDiffLine || {});
643+
const newLineHasChange = DiffLine.prototype.isIncludeableLine.call(newDiffLine || {});
638644
const len = this.#splitRightLines.length;
639645
const isHidden = !oldDiffLine && !newDiffLine;
640646

@@ -808,13 +814,19 @@ export class DiffFile {
808814
const maxOldFileLineNumber = this.#oldFileResult?.maxLineNumber || 0;
809815
const maxNewFileLineNumber = this.#newFileResult?.maxLineNumber || 0;
810816

817+
if (__DEV__ && !this.#oldFileResult && !this.#newFileResult) {
818+
console.error(
819+
"this instance can not `buildUnifiedDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
820+
);
821+
}
822+
811823
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
812824
const oldRawLine = this.#getOldRawLine(oldFileLineNumber);
813825
const oldDiffLine = this.#getOldDiffLine(oldFileLineNumber);
814826
const newRawLine = this.#getNewRawLine(newFileLineNumber);
815827
const newDiffLine = this.#getNewDiffLine(newFileLineNumber);
816-
const oldLineHasChange = oldDiffLine?.isIncludeableLine();
817-
const newLineHasChange = newDiffLine?.isIncludeableLine();
828+
const oldLineHasChange = DiffLine.prototype.isIncludeableLine.call(oldDiffLine || {});
829+
const newLineHasChange = DiffLine.prototype.isIncludeableLine.call(newDiffLine || {});
818830
const len = this.#unifiedLines.length;
819831
const isHidden = !oldDiffLine && !newDiffLine;
820832

@@ -1424,9 +1436,9 @@ export class DiffFile {
14241436
_mergeFullBundle = (data: ReturnType<DiffFile["_getFullBundle"]>, notifyUpdate = true) => {
14251437
this.mergeBundle(data, notifyUpdate);
14261438
try {
1427-
this.#oldFileResult = File.createInstance(data.oldFileResult);
1439+
this.#oldFileResult = data.oldFileResult ? File.createInstance(data.oldFileResult) : null;
14281440

1429-
this.#newFileResult = File.createInstance(data.newFileResult);
1441+
this.#newFileResult = data.newFileResult ? File.createInstance(data.newFileResult) : null;
14301442

14311443
this.#diffLines = data.diffLines;
14321444

packages/core/src/parse/change-range.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export enum NewLineSymbol {
88
LF = 3,
99
NEWLINE = 4,
1010
NORMAL = 5,
11+
NULL = 6,
1112
}
1213

1314
export interface IRange {
@@ -81,10 +82,22 @@ function checkNewLineSymbolChange(
8182
const bEndStr = stringB.slice(-2);
8283

8384
const aSymbol =
84-
aEndStr === "\r\n" ? NewLineSymbol.CRLF : aEndStr.endsWith("\r") ? NewLineSymbol.CR : NewLineSymbol.LF;
85+
aEndStr === "\r\n"
86+
? NewLineSymbol.CRLF
87+
: aEndStr.endsWith("\r")
88+
? NewLineSymbol.CR
89+
: aEndStr.endsWith("\n")
90+
? NewLineSymbol.LF
91+
: NewLineSymbol.NULL;
8592

8693
const bSymbol =
87-
bEndStr === "\r\n" ? NewLineSymbol.CRLF : bEndStr.endsWith("\r") ? NewLineSymbol.CR : NewLineSymbol.LF;
94+
bEndStr === "\r\n"
95+
? NewLineSymbol.CRLF
96+
: bEndStr.endsWith("\r")
97+
? NewLineSymbol.CR
98+
: bEndStr.endsWith("\n")
99+
? NewLineSymbol.LF
100+
: NewLineSymbol.NULL;
88101

89102
const hasNewLineChanged = addition.noTrailingNewLine !== deletion.noTrailingNewLine;
90103

@@ -98,13 +111,23 @@ function checkNewLineSymbolChange(
98111
? NewLineSymbol.NEWLINE
99112
: NewLineSymbol.NORMAL
100113
: aSymbol,
101-
addString: aSymbol === NewLineSymbol.CRLF ? stringA.slice(0, -2) : stringA.slice(0, -1),
114+
addString:
115+
aSymbol === NewLineSymbol.CRLF
116+
? stringA.slice(0, -2)
117+
: aSymbol === NewLineSymbol.CR || aSymbol === NewLineSymbol.LF
118+
? stringA.slice(0, -1)
119+
: stringA,
102120
delSymbol: hasNewLineChanged
103121
? deletion.noTrailingNewLine
104122
? NewLineSymbol.NEWLINE
105123
: NewLineSymbol.NORMAL
106124
: bSymbol,
107-
delString: bSymbol === NewLineSymbol.CRLF ? stringB.slice(0, -2) : stringB.slice(0, -1),
125+
delString:
126+
bSymbol === NewLineSymbol.CRLF
127+
? stringB.slice(0, -2)
128+
: bSymbol === NewLineSymbol.CR || bSymbol === NewLineSymbol.LF
129+
? stringB.slice(0, -1)
130+
: stringB,
108131
};
109132
}
110133

packages/core/src/parse/diff-line.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ export class DiffLine {
5050
}
5151

5252
public clone(text: string) {
53-
return new DiffLine(text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber);
53+
return new DiffLine(
54+
text,
55+
this.type,
56+
this.originalLineNumber,
57+
this.oldLineNumber,
58+
this.newLineNumber,
59+
this.noTrailingNewLine
60+
);
5461
}
5562
}
5663

packages/file/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ export declare enum NewLineSymbol {
407407
CR = 2,
408408
LF = 3,
409409
NEWLINE = 4,
410-
NORMAL = 5
410+
NORMAL = 5,
411+
NULL = 6
411412
}
412413
export declare function _getAST(raw: string, fileName?: string, lang?: DiffHighlighterLang, theme?: "light" | "dark"): DiffAST;
413414
export declare function _getAST(raw: string, fileName?: string, lang?: string, theme?: "light" | "dark"): DiffAST;

packages/react/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ export declare enum NewLineSymbol {
407407
CR = 2,
408408
LF = 3,
409409
NEWLINE = 4,
410-
NORMAL = 5
410+
NORMAL = 5,
411+
NULL = 6
411412
}
412413
export declare function _getAST(raw: string, fileName?: string, lang?: DiffHighlighterLang, theme?: "light" | "dark"): DiffAST;
413414
export declare function _getAST(raw: string, fileName?: string, lang?: string, theme?: "light" | "dark"): DiffAST;

0 commit comments

Comments
 (0)