Skip to content

Commit 9fe3a7a

Browse files
update
1 parent cd46a8a commit 9fe3a7a

26 files changed

Lines changed: 1185 additions & 367 deletions

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,26 @@ export class DiffParser {
180180
private parseDiffHeader(): IDiffHeaderInfo | null {
181181
// TODO: There's information in here that we might want to
182182
// capture, such as mode changes
183+
// check valid header
184+
let hasMinus = false;
183185
while (this.nextLine()) {
184186
if (this.lineStartsWith("Binary files ") && this.lineEndsWith("differ")) {
187+
if (__DEV__) {
188+
console.warn(
189+
"Found binary file marker in diff header, @git-diff-view/core currently does not support rendering binary diffs"
190+
);
191+
}
185192
return { isBinary: true };
186193
}
187194

195+
if (this.lineStartsWith("---")) {
196+
hasMinus = true;
197+
}
198+
188199
if (this.lineStartsWith("+++")) {
200+
if (__DEV__ && !hasMinus) {
201+
console.error("Invalid diff header, found +++ line before --- line");
202+
}
189203
return { isBinary: false };
190204
}
191205
}

ui/react-example/src/App.tsx

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@ import {
1111
Anchor,
1212
Tooltip,
1313
} from "@mantine/core";
14-
import { useDisclosure } from "@mantine/hooks";
14+
import { useDisclosure, useViewportSize } from "@mantine/hooks";
1515
import { IconBrandGithub, IconMoon, IconSun } from "@tabler/icons-react";
1616
import { version } from "react";
1717

1818
import { DevTool } from "./components/DevTool";
19-
import { ExampleContent } from "./components/ExampleContent";
2019
import { Github } from "./components/icons";
21-
import { MainContent } from "./components/MainContent";
22-
import { PlayGround } from "./components/PlayGroundContent";
23-
import { StartContent } from "./components/StartContent";
2420
import { usePreviewTypeWithRouter } from "./hooks/usePreviewType";
21+
import { Example } from "./views/Example";
22+
import { Main } from "./views/Main";
23+
import { PlayGround } from "./views/PlayGround";
24+
import { WorkerExample } from "./views/Worker";
2525

2626
function App() {
2727
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
2828

29+
const { width } = useViewportSize();
30+
2931
const type = usePreviewTypeWithRouter();
3032

3133
const [opened, { toggle, close }] = useDisclosure();
3234

33-
const goto = (type: "main" | "example" | "try") => {
35+
const goto = (type: "main" | "example" | "try" | "worker") => {
3436
const url = new URL(window.location.href);
3537
url.searchParams.set("type", type);
3638
url.searchParams.delete("tab");
@@ -51,12 +53,16 @@ function App() {
5153
<Title order={1} className="text-xl">
5254
Git Diff View
5355
</Title>
54-
<small className="ml-4 mr-1">power by</small>
55-
<Tooltip label={<span>Go to @my-react project, version: {version}</span>} withArrow position="top">
56-
<Anchor href="https://github.com/MrWangJustToDo/MyReact" target="_blank">
57-
<small>@my-react</small>
58-
</Anchor>
59-
</Tooltip>
56+
{width > 900 && (
57+
<>
58+
<small className="ml-4 mr-1">power by</small>
59+
<Tooltip label={<span>Go to @my-react project, version: {version}</span>} withArrow position="top">
60+
<Anchor href="https://github.com/MrWangJustToDo/MyReact" target="_blank">
61+
<small>@my-react</small>
62+
</Anchor>
63+
</Tooltip>
64+
</>
65+
)}
6066
</Flex>
6167
<Flex columnGap="16" visibleFrom="sm">
6268
<Button variant="light" color={type === "main" ? "blue" : "gray"} onClick={() => goto("main")}>
@@ -68,6 +74,9 @@ function App() {
6874
<Button variant="light" color={type === "try" ? "blue" : "gray"} onClick={() => goto("try")}>
6975
Playground
7076
</Button>
77+
<Button variant="light" color={type === "worker" ? "blue" : "gray"} onClick={() => goto("worker")}>
78+
Worker
79+
</Button>
7180
<Button
7281
variant="default"
7382
color="gray"
@@ -135,25 +144,13 @@ function App() {
135144
</Button>
136145
</AppShell.Navbar>
137146
<AppShell.Main>
138-
{type === "main" && (
139-
<>
140-
<MainContent />
141-
<StartContent />
142-
<DevTool />
143-
</>
144-
)}
147+
{type === "main" && <Main />}
145148
{type === "example" && (
146-
<>
147-
<ExampleContent className="border-color h-[calc(100vh-60px-32px)] w-full overflow-hidden rounded-md border" />
148-
<DevTool />
149-
</>
150-
)}
151-
{type === "try" && (
152-
<>
153-
<PlayGround />
154-
<DevTool />
155-
</>
149+
<Example className="border-color h-[calc(100vh-60px-32px)] w-full overflow-hidden rounded-md border" />
156150
)}
151+
{type === "try" && <PlayGround />}
152+
{type === "worker" && <WorkerExample />}
153+
<DevTool />
157154
</AppShell.Main>
158155
</AppShell>
159156
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const DiffViewWithScrollBar = (props: Omit<DiffViewProps<string[]>, "data
8787

8888
return (
8989
<div ref={ref}>
90-
<DiffView {...props} />
90+
<DiffView {...props} diffViewTheme={colorScheme === "dark" ? "dark" : "light"} />
9191
<div data-scroll-target className="sticky bottom-0 mt-[-6px] flex h-[6px] w-full">
9292
{diffViewMode & DiffModeEnum.Split ? (
9393
<>

ui/react-example/src/components/MainContentDiffConfig.tsx renamed to ui/react-example/src/components/MainContent/MainContentDiffConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DiffModeEnum } from "@git-diff-view/react";
22
import { Button, Group, Tooltip } from "@mantine/core";
33
import { useEffect, useState } from "react";
44

5-
import { useDiffConfig } from "../hooks/useDiffConfig";
5+
import { useDiffConfig } from "../../hooks/useDiffConfig";
66

77
import type { DiffFile } from "@git-diff-view/react";
88

ui/react-example/src/components/MainContentDiffExample.tsx renamed to ui/react-example/src/components/MainContent/MainContentDiffExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useDisclosure, useMounted } from "@mantine/hooks";
44
import { IconCode, IconPlayerPlay, IconRefresh, IconBrandReact, IconBrandVue } from "@tabler/icons-react";
55
import { useState, startTransition, useCallback, forwardRef, useMemo, useEffect } from "react";
66

7-
import { useDiffHighlighter } from "../hooks/useDiffHighlighter";
7+
import { useDiffHighlighter } from "../../hooks/useDiffHighlighter";
88

99
import { MainContentDiffExampleCode } from "./MainContentDiffExampleCode";
1010
import { temp1, temp2 } from "./MainContentDiffExampleData";

ui/react-example/src/components/MainContentDiffExampleCode.tsx renamed to ui/react-example/src/components/MainContent/MainContentDiffExampleCode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DiffModeEnum } from "@git-diff-view/react";
33
import { useMantineColorScheme } from "@mantine/core";
44
import { memo } from "react";
55

6-
import { useDiffConfig } from "../hooks/useDiffConfig";
6+
import { useDiffConfig } from "../../hooks/useDiffConfig";
77

88
const getCode = ({ theme, type }: { theme: "light" | "dark"; type: "react" | "vue" }) => {
99
return type === "react"

ui/react-example/src/components/MainContentDiffExampleData.ts renamed to ui/react-example/src/components/MainContent/MainContentDiffExampleData.ts

File renamed without changes.

ui/react-example/src/components/MainContentDiffExampleView.tsx renamed to ui/react-example/src/components/MainContent/MainContentDiffExampleView.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { Box, Button, Card, CloseButton, Group, Stack, useMantineColorScheme, Te
33
import { usePrevious } from "@mantine/hooks";
44
import { memo, useEffect, useState } from "react";
55

6-
import { useDiffConfig } from "../hooks/useDiffConfig";
7-
8-
import { DiffViewWithScrollBar } from "./DiffViewWithScrollBar";
9-
import { Textarea } from "./TextArea";
6+
import { useDiffConfig } from "../../hooks/useDiffConfig";
7+
import { DiffViewWithScrollBar } from "../DiffViewWithScrollBar";
8+
import { Textarea } from "../TextArea";
109

1110
import type { DiffFile, DiffViewProps } from "@git-diff-view/react";
1211

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from "./MainContentDiffConfig";
2+
export * from "./MainContentDiffExample";
3+
export * from "./MainContentDiffExampleCode";
4+
export * from "./MainContentDiffExampleData";
5+
export * from "./MainContentDiffExampleView";

ui/react-example/src/components/ReactPlayGround.tsx renamed to ui/react-example/src/components/PlayGround/ReactPlayGround.tsx

File renamed without changes.

0 commit comments

Comments
 (0)