Skip to content

Commit 75e48dc

Browse files
update
1 parent 4462106 commit 75e48dc

File tree

8 files changed

+38
-25
lines changed

8 files changed

+38
-25
lines changed

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/core",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -52,7 +52,7 @@
5252
"diff parse"
5353
],
5454
"dependencies": {
55-
"@git-diff-view/lowlight": "^0.0.19",
55+
"@git-diff-view/lowlight": "^0.0.20",
5656
"highlight.js": "^11.9.0",
5757
"lowlight": "^3.1.0",
5858
"fast-diff": "^1.3.0"

packages/file/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/file",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -52,7 +52,7 @@
5252
"diff parse"
5353
],
5454
"dependencies": {
55-
"@git-diff-view/core": "^0.0.19",
55+
"@git-diff-view/core": "^0.0.20",
5656
"diff": "^5.2.0",
5757
"highlight.js": "^11.9.0",
5858
"lowlight": "^3.1.0",

packages/lowlight/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/lowlight",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/react",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -61,7 +61,7 @@
6161
"react diff component"
6262
],
6363
"dependencies": {
64-
"@git-diff-view/core": "^0.0.19",
64+
"@git-diff-view/core": "^0.0.20",
6565
"@types/hast": "^3.0.0",
6666
"fast-diff": "^1.3.0",
6767
"highlight.js": "^11.9.0",

packages/shiki/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/shiki",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"types": "index.d.ts",
88
"type": "module",
99
"files": [

packages/vue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/vue",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.19",
6+
"version": "0.0.20",
77
"main": "index.js",
88
"type": "module",
99
"types": "index.d.ts",
@@ -49,7 +49,7 @@
4949
"vue diff component"
5050
],
5151
"dependencies": {
52-
"@git-diff-view/core": "^0.0.19",
52+
"@git-diff-view/core": "^0.0.20",
5353
"@types/hast": "^3.0.0",
5454
"highlight.js": "^11.9.0",
5555
"lowlight": "^3.1.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/react-example/src/components/PlayGroundContent.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { generateDiffFile } from "@git-diff-view/file";
22
import { DiffView, DiffFile } from "@git-diff-view/react";
3-
import { Button, Code, useMantineColorScheme } from "@mantine/core";
3+
import { Button, Code, Switch, useMantineColorScheme } from "@mantine/core";
44
import { debounce } from "lodash";
55
import { useCallback, useEffect, useState } from "react";
66

@@ -50,9 +50,11 @@ const _PlayGroundGitDiff = ({ onClick }: { onClick: () => void }) => {
5050

5151
return (
5252
<div className="m-auto mb-[1em] mt-[1em] w-[90%]">
53-
<h2 className="text-[24px]">
54-
<Code className="text-[24px]">Git diff</Code> mode
55-
<div className="ml-4 inline-block text-[14px]">
53+
<h2 className="flex flex-wrap gap-x-8 gap-y-4 text-[24px]">
54+
<span>
55+
<Code className="text-[24px]">Git diff</Code> mode
56+
</span>
57+
<div className="inline-block text-[14px]">
5658
<Button onClick={onClick}>Go to `File diff` mode</Button>
5759
</div>
5860
</h2>
@@ -107,6 +109,8 @@ const _PlayGroundFileDiff = ({ onClick }: { onClick: () => void }) => {
107109

108110
const [lang2, setLang2] = useState("ts");
109111

112+
const [ignoreWhiteSpace, setIgnoreWhiteSpace] = useState(false);
113+
110114
const [file1, setFile1] = useState(
111115
'import { createLowlight, all } from "lowlight";\n\nimport { processAST, type SyntaxLine } from "./processAST";\n\nconst lowlight = createLowlight(all);\n\n// !SEE https://github.com/highlightjs/highlightjs-vue\n\nlowlight.register("vue", function hljsDefineVue(hljs) {\n return {\n subLanguage: "xml",\n contains: [\n hljs.COMMENT("\x3C!--", "-->", {\n relevance: 10,\n }),\n {\n begin: /^(\\s*)(\x3Cscript>)/gm,\n end: /^(\\s*)(<\\/script>)/gm,\n subLanguage: "javascript",\n excludeBegin: true,\n excludeEnd: true,\n },\n {\n begin: /^(?:\\s*)(?:\x3Cscript\\s+lang=(["\'])ts\\1>)/gm,\n end: /^(\\s*)(<\\/script>)/gm,\n subLanguage: "typescript",\n excludeBegin: true,\n excludeEnd: true,\n },\n {\n begin: /^(\\s*)(<style(\\s+scoped)?>)/gm,\n end: /^(\\s*)(<\\/style>)/gm,\n subLanguage: "css",\n excludeBegin: true,\n excludeEnd: true,\n },\n {\n begin: /^(?:\\s*)(?:<style(?:\\s+scoped)?\\s+lang=(["\'])(?:s[ca]ss)\\1(?:\\s+scoped)?>)/gm,\n end: /^(\\s*)(<\\/style>)/gm,\n subLanguage: "scss",\n excludeBegin: true,\n excludeEnd: true,\n },\n {\n begin: /^(?:\\s*)(?:<style(?:\\s+scoped)?\\s+lang=(["\'])stylus\\1(?:\\s+scoped)?>)/gm,\n end: /^(\\s*)(<\\/style>)/gm,\n subLanguage: "stylus",\n excludeBegin: true,\n excludeEnd: true,\n },\n ],\n };\n});\n\nexport type DiffAST = ReturnType<typeof lowlight.highlight>;\n\nexport type DiffHighlighter = {\n name: string;\n maxLineToIgnoreSyntax: number;\n setMaxLineToIgnoreSyntax: (v: number) => void;\n ignoreSyntaxHighlightList: (string | RegExp)[];\n setIgnoreSyntaxHighlightList: (v: (string | RegExp)[]) => void;\n getAST: (raw: string, fileName?: string, lang?: string) => DiffAST;\n processAST: (ast: DiffAST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };\n hasRegisteredCurrentLang: (lang: string) => boolean;\n getHighlighterEngine: () => typeof lowlight;\n};\n\nconst instance = { name: "lowlight" };\n\nlet _maxLineToIgnoreSyntax = 2000;\n\nconst _ignoreSyntaxHighlightList: (string | RegExp)[] = [];\n\nObject.defineProperty(instance, "maxLineToIgnoreSyntax", {\n get: () => _maxLineToIgnoreSyntax,\n});\n\nObject.defineProperty(instance, "setMaxLineToIgnoreSyntax", {\n value: (v: number) => {\n _maxLineToIgnoreSyntax = v;\n },\n});\n\nObject.defineProperty(instance, "ignoreSyntaxHighlightList", {\n get: () => _ignoreSyntaxHighlightList,\n});\n\nObject.defineProperty(instance, "setIgnoreSyntaxHighlightList", {\n value: (v: (string | RegExp)[]) => {\n _ignoreSyntaxHighlightList.length = 0;\n _ignoreSyntaxHighlightList.push(...v);\n },\n});\n\nObject.defineProperty(instance, "getAST", {\n value: (raw: string, fileName?: string, lang?: string) => {\n let hasRegisteredLang = true;\n\n if (!lowlight.registered(lang)) {\n __DEV__ && console.warn(`not support current lang: ${lang} yet`);\n hasRegisteredLang = false;\n }\n\n if (\n fileName &&\n highlighter.ignoreSyntaxHighlightList.some((item) =>\n item instanceof RegExp ? item.test(fileName) : fileName === item\n )\n ) {\n __DEV__ &&\n console.warn(\n `ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}`\n );\n return;\n }\n\n if (hasRegisteredLang) {\n return lowlight.highlight(lang, raw);\n } else {\n return lowlight.highlightAuto(raw);\n }\n },\n});\n\nObject.defineProperty(instance, "processAST", {\n value: (ast: DiffAST) => {\n return processAST(ast);\n },\n});\n\nObject.defineProperty(instance, "hasRegisteredCurrentLang", {\n value: (lang: string) => {\n return lowlight.registered(lang);\n },\n});\n\nexport { processAST } from "./processAST";\n\nexport const versions = __VERSION__;\n\nexport const highlighter: DiffHighlighter = instance as DiffHighlighter;\n'
112116
);
@@ -120,13 +124,13 @@ const _PlayGroundFileDiff = ({ onClick }: { onClick: () => void }) => {
120124
const [diffInstance, setDiffInstance] = useState<DiffFile>();
121125

122126
const setDiffInstanceCb = useCallback(
123-
debounce((lang1, lang2, file1, file2) => {
127+
debounce((lang1, lang2, file1, file2, ignoreWhiteSpace) => {
124128
if (!file1 && !file2) {
125129
setDiffInstance(undefined);
126130
return;
127131
}
128132
const data = generateDiffFile(`foo.${lang1}`, file1, `foo.${lang2}`, file2, lang1, lang2, {
129-
ignoreWhitespace: true,
133+
ignoreWhitespace: ignoreWhiteSpace,
130134
});
131135
try {
132136
data?.init();
@@ -140,16 +144,25 @@ const _PlayGroundFileDiff = ({ onClick }: { onClick: () => void }) => {
140144
);
141145

142146
useEffect(() => {
143-
setDiffInstanceCb(lang1, lang2, file1, file2);
144-
}, [file1, file2, lang1, lang2]);
147+
setDiffInstanceCb(lang1, lang2, file1, file2, ignoreWhiteSpace);
148+
}, [file1, file2, lang1, lang2, ignoreWhiteSpace]);
145149

146150
return (
147151
<div className="m-auto mb-[1em] mt-[1em] w-[90%]">
148-
<h2 className="text-[24px]">
149-
<Code className="text-[24px]">File diff</Code> mode
150-
<div className="ml-4 inline-block text-[14px]">
152+
<h2 className="flex flex-wrap gap-x-8 gap-y-4 text-[24px]">
153+
<span>
154+
<Code className="text-[24px]">File diff</Code> mode
155+
</span>
156+
<div className="inline-block text-[14px]">
151157
<Button onClick={onClick}>Go to `Git diff` mode</Button>
152158
</div>
159+
<div className="inline-flex">
160+
<Switch
161+
checked={ignoreWhiteSpace}
162+
onChange={(e) => setIgnoreWhiteSpace(e.target.checked)}
163+
label="Ignore WhiteSpace"
164+
/>
165+
</div>
153166
</h2>
154167
<div className="mt-[10px] flex gap-x-[10px]">
155168
<div className="flex w-[50%] flex-col gap-y-[10px]">

0 commit comments

Comments
 (0)