@lukstei/util-review-ui 0.0.0-stage → 0.2.2-rc.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +83 -2
- package/package.json +59 -3
- package/scripts/pane-css.ts +31 -0
- package/src/client/CodeFileView.tsx +107 -0
- package/src/client/FileList.tsx +254 -0
- package/src/client/FileReview.tsx +45 -0
- package/src/client/GitDiffPane.module.css +599 -0
- package/src/client/ReviewCard.tsx +112 -0
- package/src/client/css.d.ts +5 -0
- package/src/client/diff.ts +184 -0
- package/src/client/quote.ts +74 -0
- package/src/client/relativeTime.ts +20 -0
- package/src/client/useLazyFile.ts +68 -0
- package/src/client/useSelectionQuote.ts +136 -0
- package/src/review.ts +58 -0
- package/src/types.ts +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lukas Steinbrecher
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lukstei/util-review-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Source-only library shared by the Git review plugin: file list, code and diff views, review card, selection quoting, and the review schemas and types. It has no Cordis entry and no bundle. Its only consumer is [`@lukstei/dsh-client-review-git`](../dsh-client-review-git/README.md).
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Use this package](#use-this-package)
|
|
10
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
11
|
+
- [Further Exploration](#further-exploration)
|
|
12
|
+
- [Model Experience](#model-experience)
|
|
13
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
14
|
+
- [Dev Note](#dev-note)
|
|
15
|
+
|
|
16
|
+
-----
|
|
17
|
+
|
|
18
|
+
<a id="use-this-package"></a>
|
|
19
|
+
## Use this package
|
|
20
|
+
|
|
21
|
+
Install `@lukstei/util-review-ui` and import from the package `exports`:
|
|
22
|
+
|
|
23
|
+
| Import | Content |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `@lukstei/util-review-ui/types` | Git review data contracts (`ReviewScope`, `ReviewTarget`, `GitSnapshot`, `GitDiffView`, `GitRepository`, ...), `COMMIT_PAGE_SIZE` (50), `MAX_BRANCH_AGE_MS` (7 days) |
|
|
26
|
+
| `@lukstei/util-review-ui/review` | Zod schemas (`reviewTargetSchema`, `branchReviewScopeSchema`, `snapshotSchema`), `GIT_REVIEW_TOOL` (`git_review_present`), `branchLabel`, `shortSha`, `commentLines` |
|
|
27
|
+
| `@lukstei/util-review-ui/client/*` | React components and hooks from [src/client/](src/client/) |
|
|
28
|
+
| `@lukstei/util-review-ui/pane-css` | Build plugin that inlines `GitDiffPane.module.css` |
|
|
29
|
+
|
|
30
|
+
Client modules: `FileList`, `FileReview`, `CodeFileView`, `ReviewCard`, `useLazyFile`, `useSelectionQuote`, `quote` (`formatQuoteContent`, `quoteToComposer`), `diff` (`createUnifiedDiff`), `relativeTime`.
|
|
31
|
+
|
|
32
|
+
Client bundles that use the components must register the exported `paneCss` plugin in their build, so the scoped CSS module ships inside the single DSH plugin script. The bundle of [`@lukstei/dsh-client-review-git`](../dsh-client-review-git/README.md) does this.
|
|
33
|
+
|
|
34
|
+
### Plugin dependencies
|
|
35
|
+
|
|
36
|
+
No plugin dependencies. Library; not mounted, no `inject`.
|
|
37
|
+
|
|
38
|
+
Used by (code imports): [`dsh-client-review-git`](../dsh-client-review-git/README.md), [`dsh-client-split-view`](../dsh-client-split-view/README.md).
|
|
39
|
+
|
|
40
|
+
-----
|
|
41
|
+
|
|
42
|
+
<a id="understand-the-implementation"></a>
|
|
43
|
+
## Understand the implementation
|
|
44
|
+
|
|
45
|
+
<details>
|
|
46
|
+
<summary>Implementation internals — click to expand</summary>
|
|
47
|
+
|
|
48
|
+
- [src/types.ts](src/types.ts): plain TypeScript contracts for host Git reads and sidebar rendering.
|
|
49
|
+
- [src/review.ts](src/review.ts): schemas and formatting helpers.
|
|
50
|
+
- [scripts/pane-css.ts](scripts/pane-css.ts): build plugin that compiles the CSS module with `lightningcss` and exports `cssText` plus scoped class names.
|
|
51
|
+
- [src/client/](src/client/): components and hooks. `useLazyFile` loads a file when expanded and aborts stale requests. `useSelectionQuote` turns a code selection into a quote payload.
|
|
52
|
+
|
|
53
|
+
Persisted state: none. Runtime deps: `@deepseek-ai/dsh-typert-protocol`, `zod`; UI primitives come from `@deepseek-ai/dsh-client-ui-primitives` at the consumer.
|
|
54
|
+
|
|
55
|
+
Tests: specs beside sources ([diff.spec.ts](src/client/diff.spec.ts), [quote.spec.ts](src/client/quote.spec.ts), [ReviewCard.spec.tsx](src/client/ReviewCard.spec.tsx), [useSelectionQuote.spec.tsx](src/client/useSelectionQuote.spec.tsx)).
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
-----
|
|
60
|
+
|
|
61
|
+
<a id="further-exploration"></a>
|
|
62
|
+
## Further Exploration
|
|
63
|
+
|
|
64
|
+
- [`@lukstei/dsh-client-review-git`](../dsh-client-review-git/README.md): the consumer.
|
|
65
|
+
|
|
66
|
+
<a id="model-experience"></a>
|
|
67
|
+
## Model Experience
|
|
68
|
+
|
|
69
|
+
No model-visible surface. This package adds no tools, prompt text, or context to the model.
|
|
70
|
+
|
|
71
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
72
|
+
## Known Limitations and Deferred Work
|
|
73
|
+
|
|
74
|
+
None.
|
|
75
|
+
|
|
76
|
+
<a id="dev-note"></a>
|
|
77
|
+
### Dev Note
|
|
78
|
+
|
|
79
|
+
<details>
|
|
80
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
81
|
+
|
|
82
|
+
`pnpm run verify` runs Biome, typecheck and tests. There is no build step.
|
|
83
|
+
|
|
84
|
+
</details>
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lukstei/util-review-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.2-rc.5.10",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/types.ts",
|
|
7
|
+
"./types": "./src/types.ts",
|
|
8
|
+
"./review": "./src/review.ts",
|
|
9
|
+
"./client/*": "./src/client/*",
|
|
10
|
+
"./pane-css": "./scripts/pane-css.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.5",
|
|
14
|
+
"lightningcss": "^1.33.0",
|
|
15
|
+
"zod": "4.6.6"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.5",
|
|
19
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
|
|
20
|
+
"@types/node": "^26.0.0",
|
|
21
|
+
"@types/react": "^19.3.0",
|
|
22
|
+
"@types/react-dom": "^19.3.0",
|
|
23
|
+
"happy-dom": "^21.0.4",
|
|
24
|
+
"react": "^19.3.1",
|
|
25
|
+
"react-dom": "^19.3.1",
|
|
26
|
+
"typescript": "^7.0.2",
|
|
27
|
+
"vitest": "5.0.5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@deepseek-ai/dsh-client-ui-conversation": "*",
|
|
31
|
+
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
32
|
+
"react": "*"
|
|
33
|
+
},
|
|
34
|
+
"description": "Shared review UI components, types and styles for DSH review and split-view plugins",
|
|
35
|
+
"files": [
|
|
36
|
+
"src",
|
|
37
|
+
"scripts",
|
|
38
|
+
"README.md",
|
|
39
|
+
"!src/**/*.spec.*",
|
|
40
|
+
"!src/**/*.test.*",
|
|
41
|
+
"!src/**/*.stories.*",
|
|
42
|
+
"!src/**/stories",
|
|
43
|
+
"!src/**/*.e2e.*",
|
|
44
|
+
"!src/**/__snapshots__",
|
|
45
|
+
"!src/**/fixtures"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/lukstei/dsh-plugins.git",
|
|
51
|
+
"directory": "packages/util-review-ui"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"check": "biome check --reporter=concise .",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run --reporter=minimal",
|
|
60
|
+
"verify": "pnpm --silent run check && pnpm --silent run typecheck && pnpm --silent run test"
|
|
61
|
+
}
|
|
6
62
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { transform } from "lightningcss";
|
|
5
|
+
|
|
6
|
+
const file = fileURLToPath(
|
|
7
|
+
new URL("../src/client/GitDiffPane.module.css", import.meta.url),
|
|
8
|
+
);
|
|
9
|
+
const moduleId = "\0git-diff-pane-css";
|
|
10
|
+
|
|
11
|
+
// edge case: DSH loads one plugin script, so scoped CSS must travel inside that script.
|
|
12
|
+
export const paneCss = {
|
|
13
|
+
name: "git-diff-pane-css",
|
|
14
|
+
resolveId(source: string) {
|
|
15
|
+
if (source.endsWith("/GitDiffPane.module.css")) return moduleId;
|
|
16
|
+
},
|
|
17
|
+
load(this: { addWatchFile(path: string): void }, id: string) {
|
|
18
|
+
if (id !== moduleId) return;
|
|
19
|
+
this.addWatchFile(file);
|
|
20
|
+
const result = transform({
|
|
21
|
+
filename: "GitDiffPane.module.css",
|
|
22
|
+
code: readFileSync(file),
|
|
23
|
+
cssModules: true,
|
|
24
|
+
});
|
|
25
|
+
assert(result.exports, "CSS Modules must export scoped class names");
|
|
26
|
+
const classes = Object.fromEntries(
|
|
27
|
+
Object.entries(result.exports).map(([key, value]) => [key, value.name]),
|
|
28
|
+
);
|
|
29
|
+
return `export const cssText = ${JSON.stringify(result.code.toString())}; export default ${JSON.stringify(classes)};`;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
CodeBlock,
|
|
4
|
+
languageForPath,
|
|
5
|
+
} from "@deepseek-ai/dsh-client-ui-primitives";
|
|
6
|
+
import { type ReactNode, useRef } from "react";
|
|
7
|
+
import styles from "./GitDiffPane.module.css";
|
|
8
|
+
import type { LazyFileResult } from "./useLazyFile.ts";
|
|
9
|
+
import { useSelectionQuote } from "./useSelectionQuote.ts";
|
|
10
|
+
|
|
11
|
+
export interface CodeQuotePayload {
|
|
12
|
+
text: string;
|
|
13
|
+
path: string;
|
|
14
|
+
lines?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function CodeFileView({
|
|
18
|
+
path,
|
|
19
|
+
code,
|
|
20
|
+
diff = false,
|
|
21
|
+
wrapped,
|
|
22
|
+
result,
|
|
23
|
+
onRetry,
|
|
24
|
+
extra,
|
|
25
|
+
onQuote,
|
|
26
|
+
}: {
|
|
27
|
+
path: string;
|
|
28
|
+
code: string | null;
|
|
29
|
+
diff?: boolean;
|
|
30
|
+
wrapped: boolean;
|
|
31
|
+
result: LazyFileResult<unknown>;
|
|
32
|
+
onRetry: () => void;
|
|
33
|
+
extra?: ReactNode;
|
|
34
|
+
onQuote?: (quote: CodeQuotePayload) => void;
|
|
35
|
+
}): ReactNode {
|
|
36
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
const { floatingQuote, clearFloatingQuote } = useSelectionQuote({
|
|
38
|
+
containerRef,
|
|
39
|
+
enabled: onQuote !== undefined,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (result.status === "loading" || result.status === "idle") {
|
|
43
|
+
return (
|
|
44
|
+
<p className={styles.note} role="status">
|
|
45
|
+
Loading file…
|
|
46
|
+
</p>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (result.status === "failed") {
|
|
50
|
+
return (
|
|
51
|
+
<p className={styles.error} role="alert">
|
|
52
|
+
{result.message}{" "}
|
|
53
|
+
<Button size="sm" variant="ghost" onClick={onRetry}>
|
|
54
|
+
Retry
|
|
55
|
+
</Button>
|
|
56
|
+
</p>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (code === null) return extra ?? null;
|
|
60
|
+
|
|
61
|
+
const handleQuote = (e: React.SyntheticEvent) => {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
if (!floatingQuote || !onQuote) return;
|
|
64
|
+
onQuote({
|
|
65
|
+
text: floatingQuote.text,
|
|
66
|
+
path,
|
|
67
|
+
lines: floatingQuote.lines,
|
|
68
|
+
});
|
|
69
|
+
clearFloatingQuote();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div ref={containerRef} className={styles.codeViewWrapper}>
|
|
74
|
+
{floatingQuote !== null && onQuote !== undefined && (
|
|
75
|
+
<div
|
|
76
|
+
className={styles.floatingQuote}
|
|
77
|
+
style={{
|
|
78
|
+
top: `${floatingQuote.top}px`,
|
|
79
|
+
left: `${floatingQuote.left}px`,
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
className={styles.floatingQuoteButton}
|
|
85
|
+
onPointerDown={(e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
}}
|
|
88
|
+
onClick={handleQuote}
|
|
89
|
+
>
|
|
90
|
+
Quote
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
{extra}
|
|
95
|
+
<CodeBlock
|
|
96
|
+
code={code}
|
|
97
|
+
lang={languageForPath(path)}
|
|
98
|
+
diff={diff}
|
|
99
|
+
lineNumbers={true}
|
|
100
|
+
wrap={wrapped}
|
|
101
|
+
showHeader={false}
|
|
102
|
+
copyLabel="Copy"
|
|
103
|
+
copiedLabel="Copied!"
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
IconChevronDownOutlineRegular,
|
|
4
|
+
} from "@deepseek-ai/dsh-client-ui-primitives";
|
|
5
|
+
import { type ReactNode, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import type { GitFileDiff, GitReviewComment } from "../types.ts";
|
|
7
|
+
import styles from "./GitDiffPane.module.css";
|
|
8
|
+
|
|
9
|
+
type Entry = { kind: "diff" } & GitFileDiff;
|
|
10
|
+
|
|
11
|
+
export function FileList(props: {
|
|
12
|
+
files: Entry[];
|
|
13
|
+
target?: GitReviewComment | null;
|
|
14
|
+
label: string;
|
|
15
|
+
isExpanded?: (path: string) => boolean;
|
|
16
|
+
onToggleExpanded?: (path: string, expanded: boolean) => void;
|
|
17
|
+
initialScrollTop?: number;
|
|
18
|
+
onScroll?: (scrollTop: number) => void;
|
|
19
|
+
renderFile: (
|
|
20
|
+
file: Entry,
|
|
21
|
+
heading: ReactNode,
|
|
22
|
+
expanded: boolean,
|
|
23
|
+
contentId: string,
|
|
24
|
+
) => ReactNode;
|
|
25
|
+
}): ReactNode {
|
|
26
|
+
const navRef = useRef<HTMLElement>(null);
|
|
27
|
+
const initialScrollRestored = useRef(false);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const nav = navRef.current;
|
|
31
|
+
if (!nav) return;
|
|
32
|
+
const container = nav.closest<HTMLElement>(`.${styles.fileTreeScroll}`);
|
|
33
|
+
if (!container) return;
|
|
34
|
+
|
|
35
|
+
if (
|
|
36
|
+
!initialScrollRestored.current &&
|
|
37
|
+
typeof props.initialScrollTop === "number" &&
|
|
38
|
+
props.initialScrollTop > 0
|
|
39
|
+
) {
|
|
40
|
+
const targetTop = props.initialScrollTop;
|
|
41
|
+
container.scrollTop = targetTop;
|
|
42
|
+
requestAnimationFrame(() => {
|
|
43
|
+
if (container.scrollTop !== targetTop) {
|
|
44
|
+
container.scrollTop = targetTop;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
initialScrollRestored.current = true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!props.onScroll) return;
|
|
51
|
+
|
|
52
|
+
let rAF: number | null = null;
|
|
53
|
+
const handleScroll = () => {
|
|
54
|
+
if (rAF !== null) cancelAnimationFrame(rAF);
|
|
55
|
+
rAF = requestAnimationFrame(() => {
|
|
56
|
+
props.onScroll?.(container.scrollTop);
|
|
57
|
+
rAF = null;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
container.addEventListener("scroll", handleScroll, { passive: true });
|
|
62
|
+
return () => {
|
|
63
|
+
if (rAF !== null) cancelAnimationFrame(rAF);
|
|
64
|
+
container.removeEventListener("scroll", handleScroll);
|
|
65
|
+
};
|
|
66
|
+
}, [props.initialScrollTop, props.onScroll]);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className={styles.fileTreeScroll}>
|
|
70
|
+
<nav ref={navRef} aria-label={props.label}>
|
|
71
|
+
<FileTree
|
|
72
|
+
{...props}
|
|
73
|
+
target={props.target ?? null}
|
|
74
|
+
directory=""
|
|
75
|
+
depth={0}
|
|
76
|
+
visible={true}
|
|
77
|
+
/>
|
|
78
|
+
</nav>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function FileTree(
|
|
84
|
+
props: Parameters<typeof FileList>[0] & {
|
|
85
|
+
directory: string;
|
|
86
|
+
depth: number;
|
|
87
|
+
visible: boolean;
|
|
88
|
+
},
|
|
89
|
+
): ReactNode {
|
|
90
|
+
const entries = Map.groupBy(
|
|
91
|
+
props.files,
|
|
92
|
+
(file) => file.path.slice(props.directory.length).split("/")[0],
|
|
93
|
+
);
|
|
94
|
+
return (
|
|
95
|
+
<ul className={styles.fileTree}>
|
|
96
|
+
{[...entries].map(([name, children]) => {
|
|
97
|
+
const path = props.directory + name;
|
|
98
|
+
const file = children.find((child) => child.path === path);
|
|
99
|
+
const descendants = children.filter((child) => child.path !== path);
|
|
100
|
+
return (
|
|
101
|
+
<li key={path}>
|
|
102
|
+
{file !== undefined && (
|
|
103
|
+
<FileEntry {...props} file={file} name={name} />
|
|
104
|
+
)}
|
|
105
|
+
{descendants.length > 0 &&
|
|
106
|
+
(() => {
|
|
107
|
+
const dir = compactDirectory(name, `${path}/`, descendants);
|
|
108
|
+
return (
|
|
109
|
+
<Directory
|
|
110
|
+
{...props}
|
|
111
|
+
files={descendants}
|
|
112
|
+
directory={dir.directory}
|
|
113
|
+
name={dir.name}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
})()}
|
|
117
|
+
</li>
|
|
118
|
+
);
|
|
119
|
+
})}
|
|
120
|
+
</ul>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function compactDirectory(
|
|
125
|
+
name: string,
|
|
126
|
+
directory: string,
|
|
127
|
+
files: Entry[],
|
|
128
|
+
): { name: string; directory: string } {
|
|
129
|
+
let currentName = name;
|
|
130
|
+
let currentDir = directory;
|
|
131
|
+
while (true) {
|
|
132
|
+
let nextSegment: string | null = null;
|
|
133
|
+
let hasDirectFile = false;
|
|
134
|
+
for (const file of files) {
|
|
135
|
+
const relative = file.path.slice(currentDir.length);
|
|
136
|
+
const slashIndex = relative.indexOf("/");
|
|
137
|
+
if (slashIndex === -1) {
|
|
138
|
+
hasDirectFile = true;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
const segment = relative.slice(0, slashIndex);
|
|
142
|
+
if (nextSegment === null) {
|
|
143
|
+
nextSegment = segment;
|
|
144
|
+
} else if (nextSegment !== segment) {
|
|
145
|
+
nextSegment = null;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (hasDirectFile || nextSegment === null) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
currentName = `${currentName}/${nextSegment}`;
|
|
153
|
+
currentDir = `${currentDir}${nextSegment}/`;
|
|
154
|
+
}
|
|
155
|
+
return { name: currentName, directory: currentDir };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function Directory(props: Parameters<typeof FileTree>[0] & { name: string }) {
|
|
159
|
+
const [open, setOpen] = useState(true);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (props.target === null || props.target === undefined) return;
|
|
162
|
+
if (props.target.path.startsWith(props.directory)) setOpen(true);
|
|
163
|
+
}, [props.target, props.directory]);
|
|
164
|
+
return (
|
|
165
|
+
<details
|
|
166
|
+
open={open}
|
|
167
|
+
onToggle={(event) => setOpen(event.currentTarget.open)}
|
|
168
|
+
>
|
|
169
|
+
<summary
|
|
170
|
+
className={styles.directory}
|
|
171
|
+
style={{ paddingInlineStart: 12 + props.depth * 16 }}
|
|
172
|
+
title={props.directory}
|
|
173
|
+
aria-label={`Directory ${props.directory.slice(0, -1)}`}
|
|
174
|
+
>
|
|
175
|
+
{props.name}
|
|
176
|
+
</summary>
|
|
177
|
+
<FileTree
|
|
178
|
+
{...props}
|
|
179
|
+
depth={props.depth + 1}
|
|
180
|
+
visible={props.visible && open}
|
|
181
|
+
/>
|
|
182
|
+
</details>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function FileEntry(
|
|
187
|
+
props: Parameters<typeof FileTree>[0] & { file: Entry; name: string },
|
|
188
|
+
) {
|
|
189
|
+
const [open, setOpen] = useState(() =>
|
|
190
|
+
props.isExpanded ? props.isExpanded(props.file.path) : false,
|
|
191
|
+
);
|
|
192
|
+
const id = useId();
|
|
193
|
+
const row = useRef<HTMLDivElement>(null);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!props.target || props.target.path !== props.file.path) return;
|
|
196
|
+
setOpen(true);
|
|
197
|
+
props.onToggleExpanded?.(props.file.path, true);
|
|
198
|
+
const frame = requestAnimationFrame(() => {
|
|
199
|
+
if (row.current !== null)
|
|
200
|
+
row.current.scrollIntoView({ block: "nearest" });
|
|
201
|
+
});
|
|
202
|
+
return () => cancelAnimationFrame(frame);
|
|
203
|
+
}, [props.target, props.file.path, props.onToggleExpanded]);
|
|
204
|
+
const file = props.file;
|
|
205
|
+
const heading = (
|
|
206
|
+
<Button
|
|
207
|
+
size="sm"
|
|
208
|
+
variant="ghost"
|
|
209
|
+
className={styles.row}
|
|
210
|
+
style={{ paddingInlineStart: 10 + props.depth * 16 }}
|
|
211
|
+
title={file.path}
|
|
212
|
+
aria-label={`${file.path} · ${file.status}`}
|
|
213
|
+
aria-expanded={open}
|
|
214
|
+
aria-controls={`${id}-content`}
|
|
215
|
+
aria-describedby={`${id}-description`}
|
|
216
|
+
onClick={() => {
|
|
217
|
+
const next = !open;
|
|
218
|
+
setOpen(next);
|
|
219
|
+
props.onToggleExpanded?.(props.file.path, next);
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
<IconChevronDownOutlineRegular
|
|
223
|
+
className={open ? styles.disclosureOpen : styles.disclosureClosed}
|
|
224
|
+
/>
|
|
225
|
+
<span className={styles.status} aria-hidden="true">
|
|
226
|
+
{{ added: "A", modified: "M", deleted: "D" }[file.status]}
|
|
227
|
+
</span>
|
|
228
|
+
{file.status === "deleted" ? (
|
|
229
|
+
<del className={styles.filename}>{props.name}</del>
|
|
230
|
+
) : (
|
|
231
|
+
<span className={styles.filename}>{props.name}</span>
|
|
232
|
+
)}
|
|
233
|
+
<span className={styles.lineCounts} aria-hidden="true">
|
|
234
|
+
<span className={styles.added}>+{file.addedLines}</span>
|
|
235
|
+
<span className={styles.deleted}>−{file.deletedLines}</span>
|
|
236
|
+
</span>
|
|
237
|
+
<span id={`${id}-description`} className={styles.visuallyHidden}>
|
|
238
|
+
{`${file.addedLines} additions, ${file.deletedLines} deletions`}
|
|
239
|
+
</span>
|
|
240
|
+
</Button>
|
|
241
|
+
);
|
|
242
|
+
return (
|
|
243
|
+
<div ref={row} className={styles.fileEntry}>
|
|
244
|
+
<div>
|
|
245
|
+
{props.renderFile(
|
|
246
|
+
file,
|
|
247
|
+
heading,
|
|
248
|
+
props.visible && open,
|
|
249
|
+
`${id}-content`,
|
|
250
|
+
)}
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
IconWrapLinesOutlineRegular,
|
|
4
|
+
Tooltip,
|
|
5
|
+
} from "@deepseek-ai/dsh-client-ui-primitives";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import styles from "./GitDiffPane.module.css";
|
|
8
|
+
|
|
9
|
+
export function FileReview({
|
|
10
|
+
heading,
|
|
11
|
+
actions,
|
|
12
|
+
expanded,
|
|
13
|
+
wrapped,
|
|
14
|
+
toggleWrap,
|
|
15
|
+
}: {
|
|
16
|
+
heading: ReactNode;
|
|
17
|
+
actions: ReactNode;
|
|
18
|
+
expanded: boolean;
|
|
19
|
+
wrapped: boolean;
|
|
20
|
+
toggleWrap: () => void;
|
|
21
|
+
}) {
|
|
22
|
+
return (
|
|
23
|
+
<div className={styles.fileHeading} data-expanded={expanded}>
|
|
24
|
+
<div className={styles.fileToolbar}>
|
|
25
|
+
{heading}
|
|
26
|
+
{expanded && (
|
|
27
|
+
<div className={styles.commentActions}>
|
|
28
|
+
{actions}
|
|
29
|
+
<Tooltip label="Wrap lines" side="bottom" align="end" portal>
|
|
30
|
+
<Button
|
|
31
|
+
size="sm"
|
|
32
|
+
className={styles.fileAction}
|
|
33
|
+
variant={wrapped ? "toolbar" : "ghost"}
|
|
34
|
+
aria-label="Wrap lines"
|
|
35
|
+
aria-pressed={wrapped}
|
|
36
|
+
icon={<IconWrapLinesOutlineRegular className={styles.icon} />}
|
|
37
|
+
onClick={toggleWrap}
|
|
38
|
+
/>
|
|
39
|
+
</Tooltip>
|
|
40
|
+
</div>
|
|
41
|
+
)}
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|